@osdk/foundry-sdk-generator 2.0.0-beta.9 → 2.0.2-rc.0
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 +243 -0
- package/bin/{foundry-sdk-generator.cjs → foundry-sdk-generator.mjs} +2 -2
- package/build/browser/index.js +33 -20
- package/build/browser/index.js.map +1 -1
- package/build/esm/generate/betaClient/generatePackage.d.ts.map +1 -1
- package/build/esm/generate/betaClient/generatePackageJson.d.ts +4 -0
- package/build/esm/generate/betaClient/generatePackageJson.d.ts.map +1 -1
- package/build/esm/index.js +33 -20
- package/build/esm/index.js.map +1 -1
- package/package.json +22 -29
- package/build/cjs/cli/foundrySdkGeneratorCli.d.cts +0 -6
- package/build/cjs/cli/foundrySdkGeneratorCli.d.ts.map +0 -1
- package/build/cjs/generate/GeneratePackageCommand.d.cts +0 -24
- package/build/cjs/generate/GeneratePackageCommand.d.ts.map +0 -1
- package/build/cjs/generate/betaClient/__tests__/bundleDependencies.test.d.cts +0 -2
- package/build/cjs/generate/betaClient/__tests__/bundleDependencies.test.d.ts.map +0 -1
- package/build/cjs/generate/betaClient/bundleDependencies.d.cts +0 -6
- package/build/cjs/generate/betaClient/bundleDependencies.d.ts.map +0 -1
- package/build/cjs/generate/betaClient/compileInMemory.d.cts +0 -18
- package/build/cjs/generate/betaClient/compileInMemory.d.ts.map +0 -1
- package/build/cjs/generate/betaClient/copyFiles.d.cts +0 -5
- package/build/cjs/generate/betaClient/copyFiles.d.ts.map +0 -1
- package/build/cjs/generate/betaClient/generatePackage.d.cts +0 -8
- package/build/cjs/generate/betaClient/generatePackage.d.ts.map +0 -1
- package/build/cjs/generate/betaClient/generatePackageJson.d.cts +0 -11
- package/build/cjs/generate/betaClient/generatePackageJson.d.ts.map +0 -1
- package/build/cjs/generate/betaClient/getModuleSourceFile.d.cts +0 -4
- package/build/cjs/generate/betaClient/getModuleSourceFile.d.ts.map +0 -1
- package/build/cjs/generate/betaClient/minifyBundle.d.cts +0 -23
- package/build/cjs/generate/betaClient/minifyBundle.d.ts.map +0 -1
- package/build/cjs/generate/commandUtils.d.cts +0 -2
- package/build/cjs/generate/commandUtils.d.ts.map +0 -1
- package/build/cjs/generate/generateBundles.d.cts +0 -2
- package/build/cjs/generate/generateBundles.d.ts.map +0 -1
- package/build/cjs/generate/index.d.cts +0 -2
- package/build/cjs/generate/index.d.ts.map +0 -1
- package/build/cjs/index.cjs +0 -881
- package/build/cjs/index.cjs.map +0 -1
- package/build/cjs/index.d.cts +0 -3
- package/build/cjs/index.d.ts.map +0 -1
- package/build/cjs/net/BaseError.d.cts +0 -8
- package/build/cjs/net/BaseError.d.ts.map +0 -1
- package/build/cjs/net/Constants.d.cts +0 -2
- package/build/cjs/net/Constants.d.ts.map +0 -1
- package/build/cjs/net/MediaType.d.cts +0 -8
- package/build/cjs/net/MediaType.d.ts.map +0 -1
- package/build/cjs/net/ResponseType.d.cts +0 -7
- package/build/cjs/net/ResponseType.d.ts.map +0 -1
- package/build/cjs/net/fetch/authenticatedFetch.d.cts +0 -8
- package/build/cjs/net/fetch/authenticatedFetch.d.ts.map +0 -1
- package/build/cjs/net/fetch/fetchFactory.d.cts +0 -13
- package/build/cjs/net/fetch/fetchFactory.d.ts.map +0 -1
- package/build/cjs/net/fetch/index.d.cts +0 -4
- package/build/cjs/net/fetch/index.d.ts.map +0 -1
- package/build/cjs/net/fetch/retryingFetch.d.cts +0 -13
- package/build/cjs/net/fetch/retryingFetch.d.ts.map +0 -1
- package/build/cjs/ontologyMetadata/Result.d.cts +0 -32
- package/build/cjs/ontologyMetadata/Result.d.ts.map +0 -1
- package/build/cjs/ontologyMetadata/index.d.cts +0 -2
- package/build/cjs/ontologyMetadata/index.d.ts.map +0 -1
- package/build/cjs/ontologyMetadata/metadataResolver.test.d.cts +0 -2
- package/build/cjs/ontologyMetadata/metadataResolver.test.d.ts.map +0 -1
- package/build/cjs/ontologyMetadata/ontologyMetadataResolver.d.cts +0 -23
- package/build/cjs/ontologyMetadata/ontologyMetadataResolver.d.ts.map +0 -1
- package/build/cjs/utils/UserAgent.d.cts +0 -2
- package/build/cjs/utils/UserAgent.d.ts.map +0 -1
- package/build/cjs/utils/index.d.cts +0 -2
- package/build/cjs/utils/index.d.ts.map +0 -1
- package/build/cjs/utils/semverUtils.d.cts +0 -2
- package/build/cjs/utils/semverUtils.d.ts.map +0 -1
- package/build/esm/net/BaseError.d.ts +0 -8
- package/build/esm/net/BaseError.d.ts.map +0 -1
- package/build/esm/net/Constants.d.ts +0 -2
- package/build/esm/net/Constants.d.ts.map +0 -1
- package/build/esm/net/MediaType.d.ts +0 -8
- package/build/esm/net/MediaType.d.ts.map +0 -1
- package/build/esm/net/ResponseType.d.ts +0 -7
- package/build/esm/net/ResponseType.d.ts.map +0 -1
- package/build/esm/net/fetch/authenticatedFetch.d.ts +0 -8
- package/build/esm/net/fetch/authenticatedFetch.d.ts.map +0 -1
- package/build/esm/net/fetch/fetchFactory.d.ts +0 -13
- package/build/esm/net/fetch/fetchFactory.d.ts.map +0 -1
- package/build/esm/net/fetch/index.d.ts +0 -4
- package/build/esm/net/fetch/index.d.ts.map +0 -1
- package/build/esm/net/fetch/retryingFetch.d.ts +0 -13
- package/build/esm/net/fetch/retryingFetch.d.ts.map +0 -1
package/build/cjs/index.cjs
DELETED
|
@@ -1,881 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var yargs = require('yargs');
|
|
4
|
-
var helpers = require('yargs/helpers');
|
|
5
|
-
var process$1 = require('process');
|
|
6
|
-
var shared_net = require('@osdk/shared.net');
|
|
7
|
-
var generator = require('@osdk/generator');
|
|
8
|
-
var promises = require('fs/promises');
|
|
9
|
-
var path = require('path');
|
|
10
|
-
var commonjs = require('@rollup/plugin-commonjs');
|
|
11
|
-
var pluginNodeResolve = require('@rollup/plugin-node-resolve');
|
|
12
|
-
var rollup = require('rollup');
|
|
13
|
-
var nodePolyfill = require('rollup-plugin-polyfill-node');
|
|
14
|
-
var tsMorph = require('ts-morph');
|
|
15
|
-
var fs = require('fs');
|
|
16
|
-
var typescript = require('typescript');
|
|
17
|
-
|
|
18
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
|
-
|
|
20
|
-
function _interopNamespace(e) {
|
|
21
|
-
if (e && e.__esModule) return e;
|
|
22
|
-
var n = Object.create(null);
|
|
23
|
-
if (e) {
|
|
24
|
-
Object.keys(e).forEach(function (k) {
|
|
25
|
-
if (k !== 'default') {
|
|
26
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function () { return e[k]; }
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
n.default = e;
|
|
35
|
-
return Object.freeze(n);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var yargs__default = /*#__PURE__*/_interopDefault(yargs);
|
|
39
|
-
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
40
|
-
var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
|
|
41
|
-
var nodePolyfill__default = /*#__PURE__*/_interopDefault(nodePolyfill);
|
|
42
|
-
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
43
|
-
|
|
44
|
-
// src/cli/foundrySdkGeneratorCli.ts
|
|
45
|
-
|
|
46
|
-
// src/ontologyMetadata/Result.ts
|
|
47
|
-
var Ok = class {
|
|
48
|
-
constructor(value) {
|
|
49
|
-
this.value = value;
|
|
50
|
-
}
|
|
51
|
-
isErr() {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
isOk() {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
transform(transformOk, _transformErr) {
|
|
58
|
-
return transformOk(this.value);
|
|
59
|
-
}
|
|
60
|
-
map(transformOk) {
|
|
61
|
-
return Result.ok(transformOk(this.value));
|
|
62
|
-
}
|
|
63
|
-
mapErr(_transformErr) {
|
|
64
|
-
return Result.ok(this.value);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
var Err = class {
|
|
68
|
-
constructor(error) {
|
|
69
|
-
this.error = error;
|
|
70
|
-
}
|
|
71
|
-
isErr() {
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
isOk() {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
transform(_transformOk, transformErr) {
|
|
78
|
-
return transformErr(this.error);
|
|
79
|
-
}
|
|
80
|
-
map(_transformOk) {
|
|
81
|
-
return Result.err(this.error);
|
|
82
|
-
}
|
|
83
|
-
mapErr(transformErr) {
|
|
84
|
-
return Result.err(transformErr(this.error));
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
var Result = {
|
|
88
|
-
ok(ok) {
|
|
89
|
-
return new Ok(ok);
|
|
90
|
-
},
|
|
91
|
-
err(err) {
|
|
92
|
-
return new Err(err);
|
|
93
|
-
},
|
|
94
|
-
/**
|
|
95
|
-
* Returns err E array if any result has an error.
|
|
96
|
-
* Returns T array if all results are ok.
|
|
97
|
-
*/
|
|
98
|
-
coalesce(results) {
|
|
99
|
-
return results.reduce((acc, value) => {
|
|
100
|
-
return value.transform((ok) => {
|
|
101
|
-
return acc.transform((accOk) => {
|
|
102
|
-
return Result.ok([...accOk, ok]);
|
|
103
|
-
}, (accErr) => {
|
|
104
|
-
return Result.err(accErr);
|
|
105
|
-
});
|
|
106
|
-
}, (err) => {
|
|
107
|
-
return acc.transform(() => {
|
|
108
|
-
return Result.err([...err]);
|
|
109
|
-
}, (accErr) => {
|
|
110
|
-
return Result.err([...accErr, ...err]);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
}, Result.ok([]));
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
// src/ontologyMetadata/ontologyMetadataResolver.ts
|
|
118
|
-
var OntologyMetadataResolver = class {
|
|
119
|
-
#authToken;
|
|
120
|
-
constructor(authToken, stackName) {
|
|
121
|
-
this.stackName = stackName;
|
|
122
|
-
this.#authToken = authToken;
|
|
123
|
-
}
|
|
124
|
-
getClientContext() {
|
|
125
|
-
return shared_net.createClientContext(this.stackName.match(/^https?:\/\//) ? this.stackName : `https://${this.stackName}`, () => this.#authToken, `foundry-typescript-osdk-generator/${process.env.npm_package_version}`);
|
|
126
|
-
}
|
|
127
|
-
filterMetadata(ontologyFullMetadata, expectedEntities) {
|
|
128
|
-
const filteredObjectTypes = Object.fromEntries(Object.entries(ontologyFullMetadata.objectTypes).filter(([objectTypeApiName]) => expectedEntities.objectTypes.has(objectTypeApiName.toLowerCase())));
|
|
129
|
-
const filteredInterfaceTypes = Object.fromEntries(Object.entries(ontologyFullMetadata.interfaceTypes).filter(([interfaceApiName]) => expectedEntities.interfaceTypes.has(interfaceApiName.toLowerCase())));
|
|
130
|
-
Object.values(filteredObjectTypes).forEach((objectType) => {
|
|
131
|
-
const linkTypesToKeep = expectedEntities.linkTypes.get(objectType.objectType.apiName.toLowerCase());
|
|
132
|
-
if (!linkTypesToKeep) {
|
|
133
|
-
objectType.linkTypes = [];
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
objectType.linkTypes = objectType.linkTypes.filter((linkType) => linkTypesToKeep.has(linkType.apiName.toLowerCase()));
|
|
137
|
-
});
|
|
138
|
-
const filteredActionTypes = Object.fromEntries(Object.entries(ontologyFullMetadata.actionTypes).filter(([actionApiName]) => {
|
|
139
|
-
if (expectedEntities.actionTypes.has(this.camelize(actionApiName).toLowerCase())) {
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
return false;
|
|
143
|
-
}));
|
|
144
|
-
const filteredQueryTypes = Object.fromEntries(Object.entries(ontologyFullMetadata.queryTypes).filter(([queryApiName]) => expectedEntities.queryTypes.has(queryApiName.toLowerCase())));
|
|
145
|
-
return {
|
|
146
|
-
ontology: ontologyFullMetadata.ontology,
|
|
147
|
-
objectTypes: filteredObjectTypes,
|
|
148
|
-
actionTypes: filteredActionTypes,
|
|
149
|
-
queryTypes: filteredQueryTypes,
|
|
150
|
-
interfaceTypes: filteredInterfaceTypes,
|
|
151
|
-
sharedPropertyTypes: {}
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
async getWireOntologyDefinition(ontologyRid, entities) {
|
|
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');
|
|
162
|
-
try {
|
|
163
|
-
ontology = await Ontologies.getOntology(this.getClientContext(), ontologyRid);
|
|
164
|
-
} catch (e) {
|
|
165
|
-
return Result.err([`Unable to load the specified Ontology with network error: ${JSON.stringify(e)}`]);
|
|
166
|
-
}
|
|
167
|
-
const ontologyFullMetadata = await OntologiesV2.getOntologyFullMetadata(this.getClientContext(), ontology.rid);
|
|
168
|
-
if (ontologyFullMetadata.errorName != null) {
|
|
169
|
-
return Result.err([`Unable to load the specified Ontology metadata.
|
|
170
|
-
${JSON.stringify(ontologyFullMetadata, null, 2)}`]);
|
|
171
|
-
}
|
|
172
|
-
const linkTypes = /* @__PURE__ */ new Map();
|
|
173
|
-
const objectTypes = new Set(entities.objectTypesApiNamesToLoad?.map((object) => object.toLowerCase()));
|
|
174
|
-
const queryTypes = new Set(entities.queryTypesApiNamesToLoad?.map((query) => query.toLowerCase()));
|
|
175
|
-
const actionTypes = new Set(entities.actionTypesApiNamesToLoad?.map((action) => this.camelize(action).toLowerCase()));
|
|
176
|
-
const interfaceTypes = new Set(entities.interfaceTypesApiNamesToLoad?.map((interfaceName) => interfaceName.toLowerCase()));
|
|
177
|
-
for (const linkType of entities.linkTypesApiNamesToLoad ?? []) {
|
|
178
|
-
const [objectTypeApiName, linkTypeApiName] = linkType.toLowerCase().split(".");
|
|
179
|
-
if (!linkTypes.has(objectTypeApiName)) {
|
|
180
|
-
linkTypes.set(objectTypeApiName, /* @__PURE__ */ new Set());
|
|
181
|
-
}
|
|
182
|
-
linkTypes.get(objectTypeApiName)?.add(linkTypeApiName);
|
|
183
|
-
}
|
|
184
|
-
const filteredFullMetadata = this.filterMetadata(ontologyFullMetadata, {
|
|
185
|
-
objectTypes,
|
|
186
|
-
linkTypes,
|
|
187
|
-
actionTypes,
|
|
188
|
-
queryTypes,
|
|
189
|
-
interfaceTypes
|
|
190
|
-
});
|
|
191
|
-
const validData = this.validateLoadedOntologyMetadata(filteredFullMetadata, {
|
|
192
|
-
objectTypes,
|
|
193
|
-
linkTypes,
|
|
194
|
-
actionTypes,
|
|
195
|
-
queryTypes
|
|
196
|
-
});
|
|
197
|
-
if (validData.isErr()) {
|
|
198
|
-
return Result.err(validData.error);
|
|
199
|
-
}
|
|
200
|
-
return Result.ok(filteredFullMetadata);
|
|
201
|
-
}
|
|
202
|
-
validateLoadedOntologyMetadata(filteredFullMetadata, expectedEntities) {
|
|
203
|
-
const errors = [];
|
|
204
|
-
const loadedObjectTypes = Object.fromEntries(Object.values(filteredFullMetadata.objectTypes).map((object) => [object.objectType.apiName.toLowerCase(), object]));
|
|
205
|
-
const loadedLinkTypes = Object.fromEntries(Object.values(filteredFullMetadata.objectTypes).map((object) => [object.objectType.apiName.toLowerCase(), Object.fromEntries(object.linkTypes.map((link) => [link.apiName.toLowerCase(), link]))]));
|
|
206
|
-
const missingObjectTypes = [];
|
|
207
|
-
for (const object of expectedEntities.objectTypes) {
|
|
208
|
-
if (!loadedObjectTypes[object]) {
|
|
209
|
-
missingObjectTypes.push(object);
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
for (const expectedLink of expectedEntities.linkTypes.get(object) ?? []) {
|
|
213
|
-
if (!loadedLinkTypes[object][expectedLink]) {
|
|
214
|
-
errors.push(`Unable to find link type ${expectedLink} for Object Type ${object}`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
for (const [, link] of Object.entries(loadedLinkTypes[object])) {
|
|
218
|
-
if (!expectedEntities.objectTypes.has(link.objectTypeApiName.toLowerCase())) {
|
|
219
|
-
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}`);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (missingObjectTypes.length > 0) {
|
|
224
|
-
errors.push(`Unable to find the following Object Types: ${missingObjectTypes.join()}`);
|
|
225
|
-
}
|
|
226
|
-
const loadedQueryTypes = Object.fromEntries(Object.entries(filteredFullMetadata.queryTypes).map(([queryApiName, query]) => [queryApiName.toLowerCase(), query]));
|
|
227
|
-
const missingQueryTypes = [];
|
|
228
|
-
for (const queryApiName of expectedEntities.queryTypes) {
|
|
229
|
-
if (!loadedQueryTypes[queryApiName]) {
|
|
230
|
-
missingQueryTypes.push(queryApiName);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
for (const query of Object.values(loadedQueryTypes)) {
|
|
234
|
-
const result = this.validateQueryParametersAndOutput(query, expectedEntities.objectTypes);
|
|
235
|
-
if (result.isErr()) {
|
|
236
|
-
for (const errorString of result.error) {
|
|
237
|
-
errors.push(errorString);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (missingQueryTypes.length > 0) {
|
|
242
|
-
errors.push(`Unable to find the following Query Types: ${missingQueryTypes.join()}`);
|
|
243
|
-
}
|
|
244
|
-
const loadedActionTypes = Object.fromEntries(Object.entries(filteredFullMetadata.actionTypes).map(([actionApiName, action]) => [this.camelize(actionApiName).toLowerCase(), action]));
|
|
245
|
-
const missingActionTypes = [];
|
|
246
|
-
for (const actionApiName of expectedEntities.actionTypes) {
|
|
247
|
-
if (!loadedActionTypes[actionApiName]) {
|
|
248
|
-
missingActionTypes.push(actionApiName);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
for (const action of Object.values(loadedActionTypes)) {
|
|
252
|
-
const result = this.validateActionParameters(action, expectedEntities.objectTypes);
|
|
253
|
-
if (result.isErr()) {
|
|
254
|
-
for (const errorString of result.error) {
|
|
255
|
-
errors.push(errorString);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
if (missingActionTypes.length > 0) {
|
|
260
|
-
errors.push(`Unable to find the following Action Types: ${missingActionTypes.join()}`);
|
|
261
|
-
}
|
|
262
|
-
if (errors.length > 0) {
|
|
263
|
-
return Result.err(errors);
|
|
264
|
-
}
|
|
265
|
-
return Result.ok({});
|
|
266
|
-
}
|
|
267
|
-
validateQueryParametersAndOutput(query, loadedObjectApiNames) {
|
|
268
|
-
const parameterValidation = Object.entries(query.parameters).map(([paramName, paramData]) => this.visitSupportedQueryTypes(query.apiName, paramName, paramData.dataType, loadedObjectApiNames));
|
|
269
|
-
parameterValidation.push(this.visitSupportedQueryTypes(query.apiName, "output", query.output, loadedObjectApiNames));
|
|
270
|
-
const results = Result.coalesce(parameterValidation);
|
|
271
|
-
return results;
|
|
272
|
-
}
|
|
273
|
-
validateActionParameters(actionType, loadedObjectApiNames) {
|
|
274
|
-
const camelizedApiName = this.camelize(actionType.apiName);
|
|
275
|
-
const parameterValidation = Object.entries(actionType.parameters).map(([_paramName, paramData]) => this.isSupportedActionTypeParameter(camelizedApiName, paramData.dataType, loadedObjectApiNames));
|
|
276
|
-
return Result.coalesce(parameterValidation);
|
|
277
|
-
}
|
|
278
|
-
visitSupportedQueryTypes(queryApiName, propertyName, baseType, loadedObjectApiNames) {
|
|
279
|
-
switch (baseType.type) {
|
|
280
|
-
case "array":
|
|
281
|
-
case "set":
|
|
282
|
-
return this.visitSupportedQueryTypes(queryApiName, propertyName, baseType.subType, loadedObjectApiNames);
|
|
283
|
-
case "objectSet":
|
|
284
|
-
case "object":
|
|
285
|
-
if (loadedObjectApiNames.has(baseType.objectTypeApiName?.toLowerCase())) {
|
|
286
|
-
return Result.ok({});
|
|
287
|
-
}
|
|
288
|
-
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}.}`]);
|
|
289
|
-
case "struct":
|
|
290
|
-
const results = baseType.fields?.map((field) => {
|
|
291
|
-
return this.visitSupportedQueryTypes(queryApiName, propertyName, field.fieldType, loadedObjectApiNames);
|
|
292
|
-
});
|
|
293
|
-
if (!results) {
|
|
294
|
-
return Result.ok({});
|
|
295
|
-
}
|
|
296
|
-
return Result.coalesce(results);
|
|
297
|
-
case "union":
|
|
298
|
-
if (baseType.unionTypes.find((unionTypes) => unionTypes.type === "null")) {
|
|
299
|
-
return Result.ok({});
|
|
300
|
-
}
|
|
301
|
-
return Result.err([`Unable to load query ${queryApiName} because it takes an unsupported parameter type: ${JSON.stringify(baseType)} in parameter ${propertyName}`]);
|
|
302
|
-
case "string":
|
|
303
|
-
case "boolean":
|
|
304
|
-
case "attachment":
|
|
305
|
-
case "date":
|
|
306
|
-
case "double":
|
|
307
|
-
case "float":
|
|
308
|
-
case "integer":
|
|
309
|
-
case "long":
|
|
310
|
-
case "threeDimensionalAggregation":
|
|
311
|
-
case "timestamp":
|
|
312
|
-
case "twoDimensionalAggregation":
|
|
313
|
-
case "null":
|
|
314
|
-
return Result.ok({});
|
|
315
|
-
case "unsupported":
|
|
316
|
-
default:
|
|
317
|
-
return Result.err([`Unable to load query ${queryApiName} because it takes an unsupported parameter type: ${JSON.stringify(baseType)} in parameter ${propertyName}`]);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
isSupportedActionTypeParameter(actionApiName, actonTypeParameter, loadedObjectApiNames) {
|
|
321
|
-
switch (actonTypeParameter.type) {
|
|
322
|
-
case "array":
|
|
323
|
-
return this.isSupportedActionTypeParameter(actionApiName, actonTypeParameter.subType, loadedObjectApiNames);
|
|
324
|
-
case "object":
|
|
325
|
-
if (loadedObjectApiNames.has(actonTypeParameter.objectTypeApiName?.toLowerCase())) {
|
|
326
|
-
return Result.ok({});
|
|
327
|
-
}
|
|
328
|
-
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})`]);
|
|
329
|
-
case "objectSet":
|
|
330
|
-
if (loadedObjectApiNames.has(actonTypeParameter.objectTypeApiName?.toLowerCase())) {
|
|
331
|
-
return Result.ok({});
|
|
332
|
-
}
|
|
333
|
-
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})`]);
|
|
334
|
-
case "string":
|
|
335
|
-
case "boolean":
|
|
336
|
-
case "attachment":
|
|
337
|
-
case "date":
|
|
338
|
-
case "double":
|
|
339
|
-
case "integer":
|
|
340
|
-
case "long":
|
|
341
|
-
case "timestamp":
|
|
342
|
-
return Result.ok({});
|
|
343
|
-
default:
|
|
344
|
-
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.`]);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
camelize(name) {
|
|
348
|
-
return name.replace(/-./g, (segment) => segment[1].toUpperCase());
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
// src/utils/semverUtils.ts
|
|
353
|
-
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-]+)*))?$/;
|
|
354
|
-
function isValidSemver(semverString) {
|
|
355
|
-
return semver.test(semverString);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// src/utils/UserAgent.ts
|
|
359
|
-
var USER_AGENT = `typescript-sdk-generator/${"2.0.0-beta.9"}`;
|
|
360
|
-
async function createRollupBuild(absolutePackagePath, packageName) {
|
|
361
|
-
const inputPath = `${absolutePackagePath}/${packageName}/index.js`;
|
|
362
|
-
const {
|
|
363
|
-
findUp
|
|
364
|
-
} = await import('find-up');
|
|
365
|
-
const nodeModulesPath = await findUp("node_modules", {
|
|
366
|
-
cwd: __dirname,
|
|
367
|
-
type: "directory"
|
|
368
|
-
});
|
|
369
|
-
return rollup.rollup({
|
|
370
|
-
input: inputPath,
|
|
371
|
-
plugins: [pluginNodeResolve.nodeResolve({
|
|
372
|
-
browser: true,
|
|
373
|
-
modulePaths: [nodeModulesPath]
|
|
374
|
-
}), ("default" in commonjs__default.default ? commonjs__default.default.default : commonjs__default.default)({}), ("default" in nodePolyfill__default.default ? nodePolyfill__default.default.default : nodePolyfill__default.default)()],
|
|
375
|
-
onwarn: (warning, warn) => {
|
|
376
|
-
if (warning.code === "CIRCULAR_DEPENDENCY") {
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
warn(warning);
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
async function writeRollupBuild(rollupBuild, absolutePackagePath, packageName, format) {
|
|
384
|
-
const outputPath = `${absolutePackagePath}/${packageName}/dist/bundle/index.${format}.js`;
|
|
385
|
-
await Promise.all([rollupBuild.write({
|
|
386
|
-
file: outputPath,
|
|
387
|
-
format,
|
|
388
|
-
name: packageName,
|
|
389
|
-
amd: {
|
|
390
|
-
id: packageName
|
|
391
|
-
},
|
|
392
|
-
plugins: []
|
|
393
|
-
})]);
|
|
394
|
-
}
|
|
395
|
-
async function generateEsmBuild(absolutePackagePath, packageName) {
|
|
396
|
-
const umdBuild = await createRollupBuild(absolutePackagePath, packageName);
|
|
397
|
-
await writeRollupBuild(umdBuild, absolutePackagePath, packageName, "esm");
|
|
398
|
-
}
|
|
399
|
-
async function generateBundles(absolutePackagePath, packageName) {
|
|
400
|
-
await Promise.all([generateEsmBuild(absolutePackagePath, packageName)]);
|
|
401
|
-
}
|
|
402
|
-
function withoutTrailingIndex(filePath) {
|
|
403
|
-
return filePath.endsWith("/index") ? filePath.slice(0, -6) : filePath;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// src/generate/betaClient/copyFiles.ts
|
|
407
|
-
var KNOWN_EXTERNAL = /* @__PURE__ */ new Set(["geojson"]);
|
|
408
|
-
function removeDts(file) {
|
|
409
|
-
return file.replace(/\.d\.c?ts$/, "");
|
|
410
|
-
}
|
|
411
|
-
async function copyFiles(project, dirs, generatedPackageName, generatedFiles) {
|
|
412
|
-
const importSet = /* @__PURE__ */ new Set();
|
|
413
|
-
for (const [fileName, file] of Object.entries(generatedFiles)) {
|
|
414
|
-
if (!fileName.endsWith(".d.ts") && !fileName.endsWith(".d.cts")) {
|
|
415
|
-
continue;
|
|
416
|
-
}
|
|
417
|
-
const indexOfPackageName = fileName.indexOf(generatedPackageName);
|
|
418
|
-
const tsPath = removeDts(fileName.slice(indexOfPackageName + generatedPackageName.length));
|
|
419
|
-
const newModulePath = `${generatedPackageName}${tsPath}`;
|
|
420
|
-
const sourceFile = project.createSourceFile(newModulePath, file);
|
|
421
|
-
for (const importDeclaration of sourceFile.getImportDeclarations()) {
|
|
422
|
-
const moduleSpecifier = importDeclaration.getModuleSpecifier();
|
|
423
|
-
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
424
|
-
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
425
|
-
if (newModuleSpecifier.startsWith("internal")) {
|
|
426
|
-
for (const importName of importDeclaration.getNamedImports().map((imp) => imp.getName())) {
|
|
427
|
-
importSet.add(importName);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
for (const exportedDecl of sourceFile.getStatements()) {
|
|
432
|
-
if (tsMorph.Node.isModifierable(exportedDecl)) {
|
|
433
|
-
exportedDecl.toggleModifier("declare", false);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
for (const exportDeclaration of sourceFile.getExportDeclarations()) {
|
|
437
|
-
const moduleSpecifier = exportDeclaration.getModuleSpecifier();
|
|
438
|
-
if (moduleSpecifier) {
|
|
439
|
-
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
440
|
-
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
441
|
-
if (newModuleSpecifier.startsWith("internal")) {
|
|
442
|
-
for (const exportName of exportDeclaration.getNamedExports().map((exp) => exp.getName())) {
|
|
443
|
-
importSet.add(exportName);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
for (const dir of dirs) {
|
|
450
|
-
const buildDirsToTry = ["build/cjs", "build/esm"];
|
|
451
|
-
const packageName = getPackageName(dir);
|
|
452
|
-
const relativeBuildDir = buildDirsToTry.find((buildDir) => {
|
|
453
|
-
return ["d.ts", "d.cts", "d.mts"].some((ext) => {
|
|
454
|
-
try {
|
|
455
|
-
fs__namespace.statSync(path__namespace.join(dir, buildDir, `index.${ext}`));
|
|
456
|
-
return true;
|
|
457
|
-
} catch (e) {
|
|
458
|
-
return false;
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
});
|
|
462
|
-
if (!relativeBuildDir) {
|
|
463
|
-
throw new Error("Couldn't find the right build dir");
|
|
464
|
-
}
|
|
465
|
-
for (const file of getTypeFiles(path__namespace.join(dir, relativeBuildDir))) {
|
|
466
|
-
const absoluteBuildDir = path__namespace.join(dir, relativeBuildDir);
|
|
467
|
-
const tsPath = removeDts(path__namespace.relative(absoluteBuildDir, file));
|
|
468
|
-
const newModulePath = `internal/${packageName}/${tsPath}`;
|
|
469
|
-
const fileContents = fs__namespace.readFileSync(file).toString();
|
|
470
|
-
const sourceFile = project.createSourceFile(`${newModulePath}.ts`, fileContents, {
|
|
471
|
-
overwrite: true
|
|
472
|
-
});
|
|
473
|
-
for (const importDeclaration of sourceFile.getImportDeclarations()) {
|
|
474
|
-
const moduleSpecifier = importDeclaration.getModuleSpecifier();
|
|
475
|
-
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
476
|
-
moduleSpecifier.setLiteralValue(newModuleSpecifier);
|
|
477
|
-
}
|
|
478
|
-
for (const exportedDecl of sourceFile.getStatements()) {
|
|
479
|
-
if (tsMorph.Node.isModifierable(exportedDecl)) {
|
|
480
|
-
exportedDecl.toggleModifier("declare", false);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
for (const exportDeclaration of sourceFile.getExportDeclarations()) {
|
|
484
|
-
const moduleSpecifier = exportDeclaration.getModuleSpecifier();
|
|
485
|
-
if (moduleSpecifier) {
|
|
486
|
-
const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
|
|
487
|
-
moduleSpecifier.setLiteralValue(withoutTrailingIndex(newModuleSpecifier));
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
return importSet;
|
|
493
|
-
}
|
|
494
|
-
function getPackageName(dir) {
|
|
495
|
-
const pkg = fs__namespace.readFileSync(path__namespace.join(dir, "package.json"));
|
|
496
|
-
const parsed = JSON.parse(pkg.toString());
|
|
497
|
-
return parsed.name;
|
|
498
|
-
}
|
|
499
|
-
function* getTypeFiles(dir) {
|
|
500
|
-
for (const item of fs__namespace.readdirSync(dir)) {
|
|
501
|
-
const target = path__namespace.join(dir, item);
|
|
502
|
-
if (target.endsWith(".d.ts") && !target.endsWith(".test.d.ts") || target.endsWith(".d.cts") && !target.endsWith(".test.d.cts")) {
|
|
503
|
-
yield target;
|
|
504
|
-
} else {
|
|
505
|
-
const stat = fs__namespace.lstatSync(target);
|
|
506
|
-
if (stat.isDirectory() && item !== "test") {
|
|
507
|
-
yield* getTypeFiles(target);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
function transformModuleSpecifier(value, filePath) {
|
|
513
|
-
let moduleSpecifier;
|
|
514
|
-
if (value.startsWith("@osdk")) {
|
|
515
|
-
if (value.startsWith("@osdk/gateway/types")) {
|
|
516
|
-
moduleSpecifier = `internal/${value.replace("@osdk/gateway/types", "@osdk/gateway/public/types")}`;
|
|
517
|
-
} else {
|
|
518
|
-
moduleSpecifier = `internal/${value}`;
|
|
519
|
-
}
|
|
520
|
-
} else if (value.startsWith(".")) {
|
|
521
|
-
moduleSpecifier = path__namespace.join(filePath, "..", value);
|
|
522
|
-
} else if (KNOWN_EXTERNAL.has(value)) {
|
|
523
|
-
moduleSpecifier = `internal/${value}`;
|
|
524
|
-
} else {
|
|
525
|
-
throw new Error("Failed generated DTS for package, no handling for: " + value);
|
|
526
|
-
}
|
|
527
|
-
return withoutTrailingIndex(withoutExtension(moduleSpecifier));
|
|
528
|
-
}
|
|
529
|
-
function withoutExtension(value) {
|
|
530
|
-
return value.replace(".js", "");
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
// src/generate/betaClient/bundleDependencies.ts
|
|
534
|
-
async function bundleDependencies(dirs, generatedPackageName, generatedFiles, entry) {
|
|
535
|
-
const project = new tsMorph.Project({
|
|
536
|
-
useInMemoryFileSystem: true,
|
|
537
|
-
compilerOptions: {
|
|
538
|
-
declaration: true,
|
|
539
|
-
emitDeclarationOnly: true,
|
|
540
|
-
outFile: "dist/bundle/index.d.ts"
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
await copyFiles(project, dirs, generatedPackageName, generatedFiles);
|
|
544
|
-
return outputModule(project);
|
|
545
|
-
}
|
|
546
|
-
function outputModule(project) {
|
|
547
|
-
const modules = [];
|
|
548
|
-
project.getSourceFiles().forEach((sourceFile) => {
|
|
549
|
-
const lines = sourceFile.getText().split("\n");
|
|
550
|
-
while (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
551
|
-
lines.pop();
|
|
552
|
-
}
|
|
553
|
-
if (lines.length === 0) {
|
|
554
|
-
return;
|
|
555
|
-
}
|
|
556
|
-
const module = [];
|
|
557
|
-
module.push(`/** ${sourceFile.getFilePath()} **/`);
|
|
558
|
-
module.push(`declare module "${withoutTrailingIndex(sourceFile.getFilePath().replace(".ts", "").replace("/", ""))}" {`);
|
|
559
|
-
for (const line of lines) {
|
|
560
|
-
const trimmed = line.trim();
|
|
561
|
-
if (trimmed.length === 0) {
|
|
562
|
-
continue;
|
|
563
|
-
}
|
|
564
|
-
module.push(` ${line}`);
|
|
565
|
-
}
|
|
566
|
-
module.push(`}`);
|
|
567
|
-
modules.push(module.join("\n"));
|
|
568
|
-
});
|
|
569
|
-
return modules.join("\n");
|
|
570
|
-
}
|
|
571
|
-
function compileInMemory(files, opts) {
|
|
572
|
-
const inMemoryOutputFileSystem = {};
|
|
573
|
-
const compilerOptions = {
|
|
574
|
-
module: opts?.esm ? typescript.ModuleKind.NodeNext : typescript.ModuleKind.CommonJS,
|
|
575
|
-
target: typescript.ScriptTarget.ES2019,
|
|
576
|
-
declaration: true,
|
|
577
|
-
skipLibCheck: true
|
|
578
|
-
};
|
|
579
|
-
const compilerHost = typescript.createCompilerHost(compilerOptions);
|
|
580
|
-
compilerHost.writeFile = (fileName, data) => {
|
|
581
|
-
inMemoryOutputFileSystem[fileName] = data;
|
|
582
|
-
};
|
|
583
|
-
const originalSourceFile = compilerHost.getSourceFile;
|
|
584
|
-
compilerHost.getSourceFile = (fileName, languageVersion) => {
|
|
585
|
-
const sourceText = files[fileName];
|
|
586
|
-
return sourceText !== void 0 ? typescript.createSourceFile(fileName, sourceText, languageVersion) : originalSourceFile(fileName, languageVersion);
|
|
587
|
-
};
|
|
588
|
-
const program = typescript.createProgram(Object.keys(files), compilerOptions, compilerHost);
|
|
589
|
-
const emitOutput = program.emit();
|
|
590
|
-
return {
|
|
591
|
-
files: inMemoryOutputFileSystem,
|
|
592
|
-
diagnostics: emitOutput.diagnostics
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
async function generatePackageJson(options) {
|
|
596
|
-
const packageDeps = options.dependencies?.reduce((acc, value) => {
|
|
597
|
-
acc[value.dependencyName] = value.dependencyVersion;
|
|
598
|
-
return acc;
|
|
599
|
-
}, {});
|
|
600
|
-
const packageJson = options.beta ? {
|
|
601
|
-
name: options.packageName,
|
|
602
|
-
version: options.packageVersion,
|
|
603
|
-
main: "./index.js",
|
|
604
|
-
types: "./index.d.ts",
|
|
605
|
-
exports: {
|
|
606
|
-
".": {
|
|
607
|
-
types: "./index.d.ts",
|
|
608
|
-
script: {
|
|
609
|
-
default: "./dist/bundle/index.esm.js"
|
|
610
|
-
},
|
|
611
|
-
default: "./index.js"
|
|
612
|
-
}
|
|
613
|
-
},
|
|
614
|
-
dependencies: packageDeps
|
|
615
|
-
} : {
|
|
616
|
-
name: options.packageName,
|
|
617
|
-
version: options.packageVersion,
|
|
618
|
-
main: "./index.js",
|
|
619
|
-
types: "./index.d.ts",
|
|
620
|
-
exports: {
|
|
621
|
-
".": {
|
|
622
|
-
types: "./index.d.ts",
|
|
623
|
-
script: {
|
|
624
|
-
types: "./dist/bundle/index.d.ts",
|
|
625
|
-
default: "./dist/bundle/index.esm.js"
|
|
626
|
-
},
|
|
627
|
-
default: "./index.js"
|
|
628
|
-
},
|
|
629
|
-
"./ontology/objects": {
|
|
630
|
-
types: "./ontology/objects/index.d.ts",
|
|
631
|
-
default: "./ontology/objects/index.js"
|
|
632
|
-
}
|
|
633
|
-
},
|
|
634
|
-
dependencies: packageDeps
|
|
635
|
-
};
|
|
636
|
-
await promises.writeFile(path.join(options.packagePath, "package.json"), JSON.stringify(packageJson, void 0, 4));
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
// src/generate/betaClient/generatePackage.ts
|
|
640
|
-
var betaDependencies = {
|
|
641
|
-
"@osdk/client.api": typeof __OSDK_CLIENT_API_VERSION__ !== "undefined" ? __OSDK_CLIENT_API_VERSION__ : void 0,
|
|
642
|
-
"@osdk/api": typeof __OSDK_API_VERSION__ !== "undefined" ? __OSDK_API_VERSION__ : void 0
|
|
643
|
-
};
|
|
644
|
-
async function generatePackage(ontology, options) {
|
|
645
|
-
const {
|
|
646
|
-
consola
|
|
647
|
-
} = await import('consola');
|
|
648
|
-
const packagePath = path.join(options.outputDir, options.packageName);
|
|
649
|
-
const resolvedDependencies = await Promise.all(Object.keys(betaDependencies).map(async (dependency) => {
|
|
650
|
-
return {
|
|
651
|
-
dependencyName: dependency,
|
|
652
|
-
dependencyVersion: await getDependencyVersion(dependency)
|
|
653
|
-
};
|
|
654
|
-
}));
|
|
655
|
-
await promises.mkdir(packagePath, {
|
|
656
|
-
recursive: true
|
|
657
|
-
});
|
|
658
|
-
const inMemoryFileSystem = {};
|
|
659
|
-
const hostFs = {
|
|
660
|
-
writeFile: async (path2, contents) => {
|
|
661
|
-
inMemoryFileSystem[path.normalize(path2)] = contents;
|
|
662
|
-
},
|
|
663
|
-
mkdir: async (path2, _options) => {
|
|
664
|
-
await promises.mkdir(path.normalize(path2), {
|
|
665
|
-
recursive: true
|
|
666
|
-
});
|
|
667
|
-
},
|
|
668
|
-
readdir: (path2) => promises.readdir(path2)
|
|
669
|
-
};
|
|
670
|
-
if (!options.beta) {
|
|
671
|
-
throw new Error("Only beta is supported in this version");
|
|
672
|
-
} else {
|
|
673
|
-
await generator.generateClientSdkVersionTwoPointZero(ontology, `typescript-sdk/${options.packageVersion} ${USER_AGENT}`, hostFs, packagePath, "module");
|
|
674
|
-
}
|
|
675
|
-
const compilerOutput = compileInMemory(inMemoryFileSystem, {
|
|
676
|
-
esm: options.beta
|
|
677
|
-
});
|
|
678
|
-
compilerOutput.diagnostics.forEach((d) => consola.error(`Error compiling file`, d.file?.fileName, d.messageText));
|
|
679
|
-
await promises.mkdir(path.join(packagePath, "dist", "bundle"), {
|
|
680
|
-
recursive: true
|
|
681
|
-
});
|
|
682
|
-
const {
|
|
683
|
-
findUp
|
|
684
|
-
} = await import('find-up');
|
|
685
|
-
const nodeModulesPath = await findUp("node_modules", {
|
|
686
|
-
cwd: __dirname,
|
|
687
|
-
type: "directory"
|
|
688
|
-
});
|
|
689
|
-
let bundleDts = "";
|
|
690
|
-
if (nodeModulesPath) {
|
|
691
|
-
try {
|
|
692
|
-
bundleDts = await bundleDependencies([], options.packageName, compilerOutput.files, void 0);
|
|
693
|
-
} catch (e) {
|
|
694
|
-
consola.error("Failed bundling DTS", e);
|
|
695
|
-
}
|
|
696
|
-
} else {
|
|
697
|
-
consola.error("Could not find node_modules directory, skipping DTS bundling");
|
|
698
|
-
}
|
|
699
|
-
await Promise.all([...Object.entries(compilerOutput.files).map(async ([path2, contents]) => {
|
|
700
|
-
await promises.writeFile(path2, contents, {
|
|
701
|
-
flag: "w"
|
|
702
|
-
});
|
|
703
|
-
}), await promises.writeFile(path.join(packagePath, "dist", "bundle", "index.d.ts"), bundleDts, {
|
|
704
|
-
flag: "w"
|
|
705
|
-
}), generatePackageJson({
|
|
706
|
-
packageName: options.packageName,
|
|
707
|
-
packagePath,
|
|
708
|
-
packageVersion: options.packageVersion,
|
|
709
|
-
dependencies: resolvedDependencies,
|
|
710
|
-
beta: options.beta
|
|
711
|
-
})]);
|
|
712
|
-
const absolutePackagePath = path.isAbsolute(options.outputDir) ? options.outputDir : path.join(process.cwd(), options.outputDir);
|
|
713
|
-
try {
|
|
714
|
-
await generateBundles(absolutePackagePath, options.packageName);
|
|
715
|
-
} catch (e) {
|
|
716
|
-
consola.error(e);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
async function getDependencyVersion(dependency) {
|
|
720
|
-
const {
|
|
721
|
-
findUp
|
|
722
|
-
} = await import('find-up');
|
|
723
|
-
const result = await findUp("package.json", {
|
|
724
|
-
cwd: __dirname
|
|
725
|
-
});
|
|
726
|
-
const packageJson = await promises.readFile(result, {
|
|
727
|
-
encoding: "utf-8"
|
|
728
|
-
});
|
|
729
|
-
if (!packageJson) {
|
|
730
|
-
throw new Error(`Could not find package.json in current working directory: ${process.cwd()}`);
|
|
731
|
-
}
|
|
732
|
-
const parsedPackageJson = JSON.parse(packageJson);
|
|
733
|
-
return parsedPackageJson.dependencies[dependency];
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
// src/generate/commandUtils.ts
|
|
737
|
-
function transformArrayArg(arg) {
|
|
738
|
-
if (arg && arg.length > 0) {
|
|
739
|
-
if (arg[0] === void 0) {
|
|
740
|
-
return void 0;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
return arg;
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
// src/generate/GeneratePackageCommand.ts
|
|
747
|
-
var GeneratePackageCommand = class {
|
|
748
|
-
command = "generatePackage";
|
|
749
|
-
describe = "Generates a new npm package which can be published";
|
|
750
|
-
constructor() {
|
|
751
|
-
}
|
|
752
|
-
builder(args) {
|
|
753
|
-
return args.positional("authToken", {
|
|
754
|
-
type: "string",
|
|
755
|
-
demandOption: true
|
|
756
|
-
}).positional("foundryHostname", {
|
|
757
|
-
type: "string",
|
|
758
|
-
demandOption: true
|
|
759
|
-
}).positional("packageName", {
|
|
760
|
-
type: "string",
|
|
761
|
-
demandOption: true,
|
|
762
|
-
description: "The name of the package to generate"
|
|
763
|
-
}).positional("packageVersion", {
|
|
764
|
-
type: "string",
|
|
765
|
-
demandOption: true,
|
|
766
|
-
description: "The version of the package to generate"
|
|
767
|
-
}).positional("outputDir", {
|
|
768
|
-
type: "string",
|
|
769
|
-
demandOption: true,
|
|
770
|
-
description: "The path where the package with the provided package name will be generated"
|
|
771
|
-
}).positional("ontology", {
|
|
772
|
-
type: "string",
|
|
773
|
-
demandOption: true,
|
|
774
|
-
description: `The ontology rid or ontology API name of the ontology to generate. Example Usage: --ontology palantirOntology`,
|
|
775
|
-
default: "ri.ontology.main.ontology.00000000-0000-0000-0000-000000000000"
|
|
776
|
-
}).options("objectTypes", {
|
|
777
|
-
array: true,
|
|
778
|
-
string: true,
|
|
779
|
-
demandOption: false,
|
|
780
|
-
description: `The API names of the object types to generate. Example Usage: --objectTypes Aircraft Airport`,
|
|
781
|
-
default: void 0,
|
|
782
|
-
defaultDescription: `By default, no arguments will not load any object type.`
|
|
783
|
-
}).options("actionTypes", {
|
|
784
|
-
array: true,
|
|
785
|
-
string: true,
|
|
786
|
-
demandOption: false,
|
|
787
|
-
description: `The API names of the action types to generate. Example Usage: --actionTypes schedule-airplane-maintenance`,
|
|
788
|
-
default: void 0,
|
|
789
|
-
defaultDescription: `By default, no arguments will not load any action type.`
|
|
790
|
-
}).options("linkTypes", {
|
|
791
|
-
array: true,
|
|
792
|
-
string: true,
|
|
793
|
-
demandOption: false,
|
|
794
|
-
description: `The link types to generate in the format of ObjectTypeApiName.LinkTypeApiName. Example Usage: --linkTypes Aircraft.scheduledFlight`,
|
|
795
|
-
default: void 0,
|
|
796
|
-
defaultDescription: `By default, no arguments will not load any link type.`
|
|
797
|
-
}).options("queryTypes", {
|
|
798
|
-
array: true,
|
|
799
|
-
string: true,
|
|
800
|
-
demandOption: false,
|
|
801
|
-
description: `The API Names of the query types to generate. Example Usage: --queryTypes calculateMetric`,
|
|
802
|
-
default: void 0,
|
|
803
|
-
defaultDescription: `By default, no arguments will not load any query type.`
|
|
804
|
-
}).options("interfaceTypes", {
|
|
805
|
-
array: true,
|
|
806
|
-
string: true,
|
|
807
|
-
demandOption: false,
|
|
808
|
-
description: `The API Names of the interface types to generate. Example Usage: --interfaceTypes Geolocatable`,
|
|
809
|
-
default: void 0,
|
|
810
|
-
defaultDescription: `By default, no arguments will not load any interface type.`
|
|
811
|
-
}).options("experimentalFeatures", {
|
|
812
|
-
array: true,
|
|
813
|
-
string: true,
|
|
814
|
-
demandOption: false,
|
|
815
|
-
description: `Experimental features that can be modified or removed at any time. Example Usage: --experimentalFeatures realtimeUpdates`,
|
|
816
|
-
default: void 0,
|
|
817
|
-
defaultDescription: `By default, no arguments will not enable any experimental features.`
|
|
818
|
-
}).options("beta", {
|
|
819
|
-
boolean: true,
|
|
820
|
-
demandOption: false,
|
|
821
|
-
hidden: true,
|
|
822
|
-
default: false
|
|
823
|
-
}).options("sdkPackages", {
|
|
824
|
-
array: true,
|
|
825
|
-
string: true,
|
|
826
|
-
// experimental for now
|
|
827
|
-
hidden: true
|
|
828
|
-
}).strict();
|
|
829
|
-
}
|
|
830
|
-
handler = async (args) => {
|
|
831
|
-
const {
|
|
832
|
-
consola
|
|
833
|
-
} = await import('consola');
|
|
834
|
-
consola.start(`Generating OSDK: ${args.packageName} at version: ${args.packageVersion}`);
|
|
835
|
-
const ontologyRid = args.ontology;
|
|
836
|
-
const ontologyMetadataResolver = new OntologyMetadataResolver(args.authToken, args.foundryHostname);
|
|
837
|
-
if (!isValidSemver(args.packageVersion)) {
|
|
838
|
-
consola.error(new Error(`Invalid argument provided for packageVersion: ${args.packageVersion}, expected valid semver`));
|
|
839
|
-
process$1.exit(1);
|
|
840
|
-
}
|
|
841
|
-
const timeStart = Date.now();
|
|
842
|
-
const wireOntologyDefinition = await ontologyMetadataResolver.getWireOntologyDefinition(ontologyRid, {
|
|
843
|
-
objectTypesApiNamesToLoad: transformArrayArg(args.objectTypes),
|
|
844
|
-
actionTypesApiNamesToLoad: transformArrayArg(args.actionTypes),
|
|
845
|
-
queryTypesApiNamesToLoad: transformArrayArg(args.queryTypes),
|
|
846
|
-
interfaceTypesApiNamesToLoad: transformArrayArg(args.interfaceTypes),
|
|
847
|
-
linkTypesApiNamesToLoad: transformArrayArg(args.linkTypes)
|
|
848
|
-
});
|
|
849
|
-
if (wireOntologyDefinition.isErr()) {
|
|
850
|
-
wireOntologyDefinition.error.forEach((err) => {
|
|
851
|
-
consola.error(err);
|
|
852
|
-
});
|
|
853
|
-
consola.error("Failed generating package");
|
|
854
|
-
process$1.exit(1);
|
|
855
|
-
}
|
|
856
|
-
await generatePackage(wireOntologyDefinition.value, {
|
|
857
|
-
packageName: args.packageName,
|
|
858
|
-
packageVersion: args.packageVersion,
|
|
859
|
-
outputDir: args.outputDir,
|
|
860
|
-
beta: !!args.beta
|
|
861
|
-
});
|
|
862
|
-
const elapsedTime = Date.now() - timeStart;
|
|
863
|
-
consola.success(`Finished generating package in ${(elapsedTime / 1e3).toFixed(2)}s`);
|
|
864
|
-
return;
|
|
865
|
-
};
|
|
866
|
-
};
|
|
867
|
-
|
|
868
|
-
// src/cli/foundrySdkGeneratorCli.ts
|
|
869
|
-
async function cli(args = process.argv) {
|
|
870
|
-
const base = yargs__default.default(helpers.hideBin(args)).command(new GeneratePackageCommand()).demandCommand().recommendCommands().strict().showHelpOnFail(true).help().version(process.env.npm_package_version);
|
|
871
|
-
try {
|
|
872
|
-
return base.parseAsync();
|
|
873
|
-
} catch (e) {
|
|
874
|
-
console.log(e);
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
exports.__testSeamOnly_NotSemverStable__GeneratePackageCommand = GeneratePackageCommand;
|
|
879
|
-
exports.cli = cli;
|
|
880
|
-
//# sourceMappingURL=index.cjs.map
|
|
881
|
-
//# sourceMappingURL=index.cjs.map
|