@osdk/generator 1.0.1 → 1.0.2
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 +7 -0
- package/build/js/index.cjs +1412 -184
- package/build/js/index.cjs.map +1 -1
- package/build/js/index.mjs +1411 -183
- package/build/js/index.mjs.map +1 -1
- package/build/types/MinimalFs.d.ts +2 -0
- package/build/types/util/test/createMockMinimalFiles.d.ts +2 -1
- package/build/types/util/verifyOutdir.d.ts +8 -0
- package/package.json +1 -1
package/build/js/index.mjs
CHANGED
|
@@ -1,68 +1,278 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
1
|
+
import * as path15 from 'path';
|
|
2
|
+
import path15__default, { join } from 'path';
|
|
3
3
|
import { format } from 'prettier';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
import organizeImports from 'prettier-plugin-organize-imports';
|
|
5
|
+
|
|
6
|
+
// src/v1.1/generateClientSdkVersionOneDotOne.ts
|
|
7
|
+
|
|
8
|
+
// src/shared/sanitizeMetadata.ts
|
|
9
|
+
function sanitizeMetadata(ontology) {
|
|
10
|
+
return {
|
|
11
|
+
...ontology,
|
|
12
|
+
actionTypes: Object.fromEntries(Object.values(ontology.actionTypes).map((actionType) => {
|
|
13
|
+
return [camelize(actionType.apiName), {
|
|
14
|
+
...actionType,
|
|
15
|
+
apiName: camelize(actionType.apiName)
|
|
16
|
+
}];
|
|
17
|
+
}))
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function camelize(name) {
|
|
21
|
+
return name.replace(/-./g, (segment) => segment[1].toUpperCase());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/util/verifyOutdir.ts
|
|
25
|
+
async function verifyOutdir(outDir, fs) {
|
|
26
|
+
try {
|
|
27
|
+
const contents = await fs.readdir(outDir);
|
|
28
|
+
if (contents.length !== 0) {
|
|
29
|
+
throw new Error(`outDir ${outDir} is not empty, please delete its contents and try again`);
|
|
30
|
+
}
|
|
31
|
+
} catch (e) {
|
|
32
|
+
if (e.code === "ENOENT") ; else {
|
|
33
|
+
throw e;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/shared/getEditedEntities.ts
|
|
39
|
+
function getModifiedEntityTypes(action) {
|
|
40
|
+
const addedObjects = /* @__PURE__ */ new Set();
|
|
41
|
+
const modifiedObjects = /* @__PURE__ */ new Set();
|
|
42
|
+
for (const operation of action.operations) {
|
|
43
|
+
switch (operation.type) {
|
|
44
|
+
case "createObject":
|
|
45
|
+
addedObjects.add(operation.objectTypeApiName);
|
|
46
|
+
break;
|
|
47
|
+
case "modifyObject":
|
|
48
|
+
modifiedObjects.add(operation.objectTypeApiName);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
addedObjects,
|
|
54
|
+
modifiedObjects
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function formatTs(contents) {
|
|
58
|
+
return format(contents, {
|
|
59
|
+
parser: "typescript",
|
|
60
|
+
singleQuote: true,
|
|
61
|
+
trailingComma: "all",
|
|
62
|
+
plugins: [organizeImports],
|
|
63
|
+
tabWidth: 2,
|
|
64
|
+
printWidth: 120
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/v1.1/generateActions.ts
|
|
69
|
+
async function generateActions(ontology, fs, outDir, importExt = "") {
|
|
70
|
+
const importedObjects = /* @__PURE__ */ new Set();
|
|
71
|
+
let actionSignatures = [];
|
|
72
|
+
for (const action of Object.values(ontology.actionTypes)) {
|
|
73
|
+
const entries = Object.entries(action.parameters);
|
|
74
|
+
const modifiedEntityTypes = getModifiedEntityTypes(action);
|
|
75
|
+
const addedObjects = Array.from(modifiedEntityTypes.addedObjects);
|
|
76
|
+
const modifiedObjects = Array.from(modifiedEntityTypes.modifiedObjects);
|
|
77
|
+
addedObjects.forEach(importedObjects.add, importedObjects);
|
|
78
|
+
modifiedObjects.forEach(importedObjects.add, importedObjects);
|
|
79
|
+
let jsDocBlock = ["/**"];
|
|
80
|
+
if (action.description) {
|
|
81
|
+
jsDocBlock.push(`* ${action.description}`);
|
|
82
|
+
}
|
|
83
|
+
let parameterBlock = "";
|
|
84
|
+
if (entries.length > 0) {
|
|
85
|
+
parameterBlock = `params: {
|
|
86
|
+
`;
|
|
87
|
+
for (const [parameterName, parameterData] of entries) {
|
|
88
|
+
parameterBlock += `"${parameterName}"`;
|
|
89
|
+
parameterBlock += parameterData.required ? ": " : "?: ";
|
|
90
|
+
const typeScriptType = getTypeScriptTypeFromDataType(parameterData.dataType, importedObjects);
|
|
91
|
+
parameterBlock += `${typeScriptType};
|
|
92
|
+
`;
|
|
93
|
+
jsDocBlock.push(`* @param {${typeScriptType}} params.${parameterName}`);
|
|
94
|
+
}
|
|
95
|
+
parameterBlock += "}, ";
|
|
96
|
+
}
|
|
97
|
+
jsDocBlock.push(`*/`);
|
|
98
|
+
actionSignatures.push(`
|
|
99
|
+
${jsDocBlock.join("\n")}
|
|
100
|
+
${action.apiName}<O extends ActionExecutionOptions>(${parameterBlock}options?: O):
|
|
101
|
+
Promise<Result<ActionResponseFromOptions<O, Edits<${addedObjects.length > 0 ? addedObjects.join(" | ") : "void"}, ${modifiedObjects.length > 0 ? modifiedObjects.join(" | ") : "void"}>>, ActionError>>;`);
|
|
102
|
+
}
|
|
103
|
+
await fs.mkdir(outDir, {
|
|
104
|
+
recursive: true
|
|
105
|
+
});
|
|
106
|
+
await fs.writeFile(path15__default.join(outDir, "Actions.ts"), await formatTs(`
|
|
13
107
|
import type { ObjectSet, LocalDate, Timestamp, Attachment, Edits, ActionExecutionOptions, ActionError, Result, ActionResponseFromOptions } from "@osdk/legacy-client";
|
|
14
|
-
${Array.from(
|
|
15
|
-
`)}
|
|
108
|
+
${Array.from(importedObjects).map((importedObject) => `import type { ${importedObject} } from "../objects/${importedObject}${importExt}";`).join("\n")}
|
|
16
109
|
export interface Actions {
|
|
17
|
-
${
|
|
18
|
-
|
|
110
|
+
${actionSignatures.join("\n")}
|
|
111
|
+
}
|
|
112
|
+
`));
|
|
113
|
+
}
|
|
114
|
+
function getTypeScriptTypeFromDataType(actionParameter, importedObjects) {
|
|
115
|
+
switch (actionParameter.type) {
|
|
116
|
+
case "objectSet": {
|
|
117
|
+
const objectType = actionParameter.objectTypeApiName;
|
|
118
|
+
importedObjects.add(objectType);
|
|
119
|
+
return `ObjectSet<${objectType}>`;
|
|
19
120
|
}
|
|
20
|
-
|
|
21
|
-
|
|
121
|
+
case "object": {
|
|
122
|
+
const objectType = actionParameter.objectTypeApiName;
|
|
123
|
+
importedObjects.add(objectType);
|
|
124
|
+
return `${objectType} | ${objectType}["__primaryKey"]`;
|
|
125
|
+
}
|
|
126
|
+
case "array":
|
|
127
|
+
return `Array<${getTypeScriptTypeFromDataType(actionParameter.subType, importedObjects)}>`;
|
|
128
|
+
case "string":
|
|
129
|
+
return `string`;
|
|
130
|
+
case "boolean":
|
|
131
|
+
return `boolean`;
|
|
132
|
+
case "attachment":
|
|
133
|
+
return `Attachment`;
|
|
134
|
+
case "date":
|
|
135
|
+
return `LocalDate`;
|
|
136
|
+
case "double":
|
|
137
|
+
case "integer":
|
|
138
|
+
case "long":
|
|
139
|
+
return `number`;
|
|
140
|
+
case "timestamp":
|
|
141
|
+
return `Timestamp`;
|
|
142
|
+
default:
|
|
143
|
+
throw new Error(`Unsupported action parameter type: ${actionParameter}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/v1.1/backcompat/util/reexportConsts.ts
|
|
148
|
+
function reexportConsts(typesToExport) {
|
|
149
|
+
return `
|
|
150
|
+
import { ${typesToExport.map((q) => `${q} as OG_${q}`).join(", ")}} from "@osdk/legacy-client";
|
|
22
151
|
|
|
23
|
-
${
|
|
152
|
+
${typesToExport.map((q) => `
|
|
24
153
|
/** @deprecated submodule imports arent public api **/
|
|
25
|
-
export const ${
|
|
26
|
-
`).join(
|
|
154
|
+
export const ${q} = OG_${q};
|
|
155
|
+
`).join("\n\n")}
|
|
156
|
+
`;
|
|
157
|
+
}
|
|
27
158
|
|
|
28
|
-
|
|
29
|
-
|
|
159
|
+
// src/v1.1/backcompat/internal-foundry-oauth-dist/generateConfidentialClientDir.ts
|
|
160
|
+
async function generateConfidentialClientDir(fs, oauthDistDir) {
|
|
161
|
+
const confidentialClientDistDir = path15__default.join(oauthDistDir, "ConfidentialClient");
|
|
162
|
+
await fs.mkdir(confidentialClientDistDir, {
|
|
163
|
+
recursive: true
|
|
164
|
+
});
|
|
165
|
+
await fs.writeFile(path15__default.join(confidentialClientDistDir, "index.ts"), await formatTs(`
|
|
30
166
|
export * from "./ConfidentialClientAuth";
|
|
31
|
-
`))
|
|
32
|
-
|
|
33
|
-
|
|
167
|
+
`));
|
|
168
|
+
await fs.writeFile(path15__default.join(confidentialClientDistDir, "ConfidentialClientAuth.ts"), await formatTs(`
|
|
169
|
+
${reexportConsts(["ConfidentialClientAuth"])}
|
|
170
|
+
`));
|
|
171
|
+
}
|
|
172
|
+
async function generatePublicClientDir(fs, oauthDistDir) {
|
|
173
|
+
const publicClientDistDir = path15__default.join(oauthDistDir, "PublicClient");
|
|
174
|
+
await fs.mkdir(publicClientDistDir, {
|
|
175
|
+
recursive: true
|
|
176
|
+
});
|
|
177
|
+
await fs.writeFile(path15__default.join(publicClientDistDir, "index.ts"), await formatTs(`
|
|
34
178
|
export * from "./PublicClientAuth";
|
|
35
|
-
`))
|
|
36
|
-
|
|
37
|
-
|
|
179
|
+
`));
|
|
180
|
+
await fs.writeFile(path15__default.join(publicClientDistDir, "PublicClientAuth.ts"), await formatTs(`
|
|
181
|
+
${reexportConsts(["PublicClientAuth"])}
|
|
182
|
+
`));
|
|
183
|
+
}
|
|
184
|
+
async function generateUserTokenDir(fs, oauthDistDir) {
|
|
185
|
+
const userTokenDistDir = path15__default.join(oauthDistDir, "UserToken");
|
|
186
|
+
await fs.mkdir(userTokenDistDir, {
|
|
187
|
+
recursive: true
|
|
188
|
+
});
|
|
189
|
+
await fs.writeFile(path15__default.join(userTokenDistDir, "index.ts"), await formatTs(`
|
|
38
190
|
export * from "./UserTokenAuth";
|
|
39
|
-
`))
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
191
|
+
`));
|
|
192
|
+
await fs.writeFile(path15__default.join(userTokenDistDir, "UserTokenAuth.ts"), await formatTs(`
|
|
193
|
+
${reexportConsts(["UserTokenAuth"])}
|
|
194
|
+
`));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// src/v1.1/backcompat/util/reexportTypes.ts
|
|
198
|
+
function reexportTypes(typesToExport, genericArgsLeft = "", genericArgsRight = cleanup(genericArgsLeft)) {
|
|
199
|
+
return `
|
|
200
|
+
import type { ${typesToExport.map((q) => `${q} as OG_${q}`).join(", ")}} from "@osdk/legacy-client";
|
|
43
201
|
|
|
44
|
-
${
|
|
202
|
+
${typesToExport.map((q) => `
|
|
45
203
|
/** @deprecated submodule imports arent public api **/
|
|
46
|
-
export type ${
|
|
47
|
-
`).join(
|
|
204
|
+
export type ${q}${genericArgsLeft} = OG_${q}${genericArgsRight};
|
|
205
|
+
`).join("\n\n")}
|
|
206
|
+
`;
|
|
207
|
+
}
|
|
208
|
+
var captureInBracketsRegex = /<(.*?)>/;
|
|
209
|
+
var captureGenericParamNameRegex = /^\s?(.+?)( extends .*?)?( = .*?)?\s?$/;
|
|
210
|
+
function cleanup(s) {
|
|
211
|
+
if (s.length === 0)
|
|
212
|
+
return "";
|
|
213
|
+
const genericParameterNames = captureInBracketsRegex.exec(s)?.[1]?.split(",")?.map((a) => {
|
|
214
|
+
return captureGenericParamNameRegex.exec(a)?.[1] ?? a;
|
|
215
|
+
});
|
|
216
|
+
return `<${genericParameterNames?.join(",")}>`;
|
|
217
|
+
}
|
|
48
218
|
|
|
49
|
-
|
|
50
|
-
|
|
219
|
+
// src/v1.1/backcompat/generateOAuthDistDir.ts
|
|
220
|
+
async function generateOAuthClientDistDir(outDir, fs) {
|
|
221
|
+
const oauthDistDir = path15.join(outDir, "internal", "@foundry", "oauth-client", "dist");
|
|
222
|
+
await fs.mkdir(oauthDistDir, {
|
|
223
|
+
recursive: true
|
|
224
|
+
});
|
|
225
|
+
await fs.writeFile(path15.join(oauthDistDir, "index.ts"), await formatTs(`
|
|
51
226
|
export * from "./Auth";
|
|
52
227
|
export * from "./ConfidentialClient";
|
|
53
228
|
export * from "./OAuthClient";
|
|
54
229
|
export * from "./PublicClient";
|
|
55
230
|
export * from "./Token";
|
|
56
231
|
export * from "./UserToken";
|
|
57
|
-
`))
|
|
232
|
+
`));
|
|
233
|
+
await fs.writeFile(path15.join(oauthDistDir, "Auth.ts"), await formatTs(reexportTypes(["Auth"])));
|
|
234
|
+
await fs.writeFile(path15.join(oauthDistDir, "Token.ts"), await formatTs(reexportTypes(["Token", "TokenValue"])));
|
|
235
|
+
await fs.writeFile(path15.join(oauthDistDir, "OAuthClient.ts"), await formatTs(reexportTypes(["AuthSubscription", "UnsubscribeFunction", "SignInResponse", "RefreshResponse", "SignOutResponse"])));
|
|
236
|
+
await fs.writeFile(path15.join(oauthDistDir, "OAuthToken.ts"), await formatTs(reexportConsts(["OAuthToken"])));
|
|
237
|
+
await fs.writeFile(path15.join(oauthDistDir, "Auth.ts"), await formatTs(reexportTypes(["Auth"])));
|
|
238
|
+
await generateConfidentialClientDir(fs, oauthDistDir);
|
|
239
|
+
await generatePublicClientDir(fs, oauthDistDir);
|
|
240
|
+
await generateUserTokenDir(fs, oauthDistDir);
|
|
241
|
+
}
|
|
242
|
+
async function generateAggregationsAggregations(fs, aggregationsDir) {
|
|
243
|
+
await fs.writeFile(path15.join(aggregationsDir, "Aggregations.ts"), await formatTs(`
|
|
58
244
|
import { LocalDate, Timestamp } from "@osdk/legacy-client";
|
|
59
|
-
|
|
60
|
-
|
|
245
|
+
` + reexportTypes(["Double", "Rangeable", "MetricValue", "Date", "BucketKey", "BucketValue", "TimeUnit", "BucketGroup", "Metrics", "AggregatableProperties", "AggregationClause"]) + reexportTypes(["Range"], "<T extends Rangeable>", "<T>") + reexportTypes(["BaseGroupBy"], "<_T extends BucketValue = BucketValue>") + reexportTypes(["Duration"], "<_T extends Timestamp | LocalDate = Timestamp | LocalDate>") + reexportTypes(["AggregatableProperty", "MultipleAggregationsOperations"], "<_T extends MetricValue = MetricValue>") + reexportTypes(["AggregationGroup"], "<TMetrics extends Metrics | MetricValue, TBucketGroup extends BucketGroup>") + reexportTypes(["Bucketing"], "<_T extends string , _X extends BucketValue>") + reexportTypes(["AggregationResult"], "<TBucketGroup extends BucketGroup, TMetrics extends Metrics | MetricValue>") + reexportTypes(["BaseBucketing"], "<TBucketKey extends BucketKey, TBucketValue extends BucketValue, Kind extends string>") + reexportTypes(["ExactValueBucketing", "InternalBucketing"], `<TBucketKey extends BucketKey, TBucketValue extends BucketValue>`) + reexportTypes(["RangeBucketing", "FixedWidthBucketing"], `<TBucketKey extends BucketKey, TBucketValue extends Range<Rangeable>>`) + reexportTypes(["DurationBucketing"], `<TBucketKey extends BucketKey, TBucketValue extends Date>`) + reexportTypes(["InternalBucketingVisitor"], "<TBucketKey extends BucketKey, T extends BucketValue, R>") + reexportTypes(["AggregationBuilderResult"], "<T, TMultipleAggregationProperties>") + reexportTypes(["AggregatablePropertiesForResult", "AggregatablePropertyNamesForResult"], "<TAggregatableProperties, TResult extends MetricValue>") + reexportConsts(["assertBucketingInternal", "visitInternalBucketing"]) + reexportTypes(["AggregatableObjectSetStep"], "<TAggregatableProperties, TMultipleAggregationProperties, TBucketableProperties, TBucketGroup extends BucketGroup = {}>") + reexportTypes(["GroupedTerminalAggregationOperations"], "<TAggregatableProperties, TMultipleAggregationProperties, TBucketGroup extends BucketGroup = {}>")));
|
|
246
|
+
}
|
|
247
|
+
async function generateGroupBy(fs, aggregationsDir) {
|
|
248
|
+
await fs.mkdir(path15.join(aggregationsDir, "groupBy"), {
|
|
249
|
+
recursive: true
|
|
250
|
+
});
|
|
251
|
+
const groupBys = ["BooleanGroupBy", "LocalDateGroupBy", "NumericGroupBy", "StringGroupBy", "TimestampGroupBy"];
|
|
252
|
+
const reexportFiles = [...groupBys, "GroupKeyType"];
|
|
253
|
+
for (const key of reexportFiles) {
|
|
254
|
+
await fs.writeFile(path15.join(aggregationsDir, "groupBy", `${key}.ts`), await formatTs(`export {${key}} from "./index";`));
|
|
255
|
+
}
|
|
256
|
+
await fs.writeFile(path15.join(aggregationsDir, "groupBy", "index.ts"), await formatTs(`import { Bucketing, BucketKey, Duration, Range, Rangeable } from "../Aggregations";` + reexportConsts(groupBys) + reexportTypes(groupBys, "<T extends BucketKey>") + `export {GroupKeyType} from "@osdk/legacy-client";
|
|
257
|
+
`));
|
|
258
|
+
}
|
|
259
|
+
async function generateMetrics(fs, aggregationsDir) {
|
|
260
|
+
const metricsDir = path15.join(aggregationsDir, "metrics");
|
|
261
|
+
await fs.mkdir(metricsDir, {
|
|
262
|
+
recursive: true
|
|
263
|
+
});
|
|
264
|
+
await fs.writeFile(path15.join(metricsDir, "metrics.ts"), await formatTs(`export {MetricValueType} from "@osdk/legacy-client";`));
|
|
265
|
+
await fs.writeFile(path15.join(metricsDir, "ApproximateDistinctCountAggregatableProperty.ts"), await formatTs(reexportConsts(["ApproximateDistinctCountAggregatableProperty"]) + reexportTypes(["ApproximateDistinctCountAggregatableProperty"])));
|
|
266
|
+
await fs.writeFile(path15.join(metricsDir, "MultipleAggregatableProperty.ts"), await formatTs(`
|
|
61
267
|
import { Double, MetricValue, MultipleAggregationsOperations } from "../Aggregations";
|
|
62
268
|
import { MetricValueType } from "./metrics";
|
|
63
|
-
|
|
269
|
+
` + reexportConsts(["MultipleAggregatableProperty"]) + reexportTypes(["MultipleAggregatableProperty"], "<TResult extends MetricValue = Double>")));
|
|
270
|
+
for (const typeName of ["DefaultAggregatableProperty", "LocalDatePropertyMetric", "NumericPropertyMetric", "TimestampPropertyMetric"]) {
|
|
271
|
+
await fs.writeFile(path15.join(metricsDir, `${typeName}.ts`), await formatTs(`
|
|
64
272
|
import { MultipleAggregatableProperty } from "./MultipleAggregatableProperty";
|
|
65
|
-
|
|
273
|
+
` + reexportConsts([typeName])));
|
|
274
|
+
}
|
|
275
|
+
await fs.writeFile(path15.join(metricsDir, "index.ts"), await formatTs(`
|
|
66
276
|
export * from "./ApproximateDistinctCountAggregatableProperty";
|
|
67
277
|
export * from "./DefaultAggregatableProperty";
|
|
68
278
|
export * from "./LocalDatePropertyMetric";
|
|
@@ -70,9 +280,21 @@ function B(e){return {...e,actionTypes:Object.fromEntries(Object.values(e.action
|
|
|
70
280
|
export * from "./MultipleAggregatableProperty";
|
|
71
281
|
export * from "./NumericPropertyMetric";
|
|
72
282
|
export * from "./TimestampPropertyMetric";
|
|
73
|
-
`));
|
|
74
|
-
|
|
75
|
-
|
|
283
|
+
`));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/v1.1/backcompat/internal-foundry-ontology-runtime-dist/generateAggregationsDir.ts
|
|
287
|
+
async function generateAggregationsDir(fs, runtimeDistDir) {
|
|
288
|
+
const aggregationsDir = path15.join(runtimeDistDir, "aggregations");
|
|
289
|
+
await fs.mkdir(aggregationsDir, {
|
|
290
|
+
recursive: true
|
|
291
|
+
});
|
|
292
|
+
await generateGroupBy(fs, aggregationsDir);
|
|
293
|
+
await generateAggregationsAggregations(fs, aggregationsDir);
|
|
294
|
+
await generateMetrics(fs, aggregationsDir);
|
|
295
|
+
await fs.writeFile(path15.join(aggregationsDir, "index.ts"), await formatTs(`
|
|
296
|
+
${""}
|
|
297
|
+
${""}
|
|
76
298
|
|
|
77
299
|
export * from "./Aggregations";
|
|
78
300
|
export * from "./ComputeStep";
|
|
@@ -80,16 +302,33 @@ function B(e){return {...e,actionTypes:Object.fromEntries(Object.values(e.action
|
|
|
80
302
|
export * from "./groupBy";
|
|
81
303
|
export * from "./internalAggregationRequest";
|
|
82
304
|
export * from "./metrics";
|
|
83
|
-
`))
|
|
305
|
+
`));
|
|
306
|
+
await fs.writeFile(path15.join(aggregationsDir, "ComputeStep.ts"), await formatTs(`
|
|
84
307
|
import { ObjectSetDefinition } from "../baseTypes";
|
|
85
308
|
import { FoundryClientOptions } from "../client";
|
|
86
309
|
import { AggregateObjectsError, OntologyMetadata, Result } from "../ontologyProvider";
|
|
87
310
|
import { AggregationClause, AggregationResult, BucketGroup, BucketValue, InternalBucketing, Metrics, MetricValue } from "./Aggregations";
|
|
88
|
-
|
|
311
|
+
` + reexportConsts(["ComputeStep"]) + reexportTypes(["ComputeStep"], "<TBucketGroup extends BucketGroup, TMetrics extends Metrics | MetricValue> ") + reexportTypes(["AggregationComputeStep"], "<TBucketGroup extends BucketGroup, TMetrics extends Metrics | MetricValue>") + `
|
|
89
312
|
|
|
90
|
-
`))
|
|
313
|
+
`));
|
|
314
|
+
await fs.writeFile(path15.join(aggregationsDir, "CountOperation.ts"), await formatTs(`` + reexportConsts(["CountOperation", "isCountOperation"]) + reexportTypes(["CountOperation"])));
|
|
315
|
+
await fs.writeFile(path15.join(aggregationsDir, "internalAggregationRequest.ts"), await formatTs(reexportTypes(["InternalAggregationRequest"])));
|
|
316
|
+
}
|
|
317
|
+
async function generateAttachmentsDir(attachmentsDir, fs) {
|
|
318
|
+
await fs.mkdir(attachmentsDir, {
|
|
319
|
+
recursive: true
|
|
320
|
+
});
|
|
321
|
+
await fs.writeFile(path15__default.join(attachmentsDir, "index.ts"), await formatTs(`export * from "./Attachment";
|
|
91
322
|
export * from "./Attachments";
|
|
92
|
-
`))
|
|
323
|
+
`));
|
|
324
|
+
await fs.writeFile(path15__default.join(attachmentsDir, "Attachment.ts"), await formatTs(reexportTypes(["Attachment", "AttachmentMetadata"])));
|
|
325
|
+
await fs.writeFile(path15__default.join(attachmentsDir, "Attachments.ts"), await formatTs(reexportTypes(["Attachments"])));
|
|
326
|
+
}
|
|
327
|
+
async function generateGeoshapesDir(runtimeDistDir, fs) {
|
|
328
|
+
await fs.mkdir(runtimeDistDir, {
|
|
329
|
+
recursive: true
|
|
330
|
+
});
|
|
331
|
+
await fs.writeFile(path15.join(runtimeDistDir, "index.ts"), await formatTs(`export * from "./Distance";
|
|
93
332
|
export * from "./GeoJson";
|
|
94
333
|
export * from "./GeometryCollection";
|
|
95
334
|
export * from "./GeoPoint";
|
|
@@ -98,19 +337,64 @@ function B(e){return {...e,actionTypes:Object.fromEntries(Object.values(e.action
|
|
|
98
337
|
export * from "./MultiGeoPoint";
|
|
99
338
|
export * from "./MultiLineString";
|
|
100
339
|
export * from "./MultiPolygon";
|
|
101
|
-
export * from "./Polygon";`))
|
|
340
|
+
export * from "./Polygon";`));
|
|
341
|
+
await fs.writeFile(path15.join(runtimeDistDir, "Distance.ts"), await formatTs(`` + reexportConsts(["Distance", "DistanceUnit"]) + reexportTypes(["Distance", "DistanceUnit"])));
|
|
342
|
+
await fs.writeFile(path15.join(runtimeDistDir, "GeoJson.ts"), await formatTs(reexportTypes(["GeoJsonPoint", "GeoJsonPolygon", "GeoJsonLineString", "GeoJsonMultiPoint", "GeoJsonMultiPolygon", "GeoJsonMultiLineString", "GeoJsonGeometryCollection", "GeoJsonGeometry", "GeoJson"])));
|
|
343
|
+
await fs.writeFile(path15.join(runtimeDistDir, "GeometryCollection.ts"), await formatTs(reexportConsts(["GeometryCollection"])));
|
|
344
|
+
await fs.writeFile(path15.join(runtimeDistDir, "GeoPoint.ts"), await formatTs(`` + reexportConsts(["isGeoPoint", "GeoPoint", "mapCoordinatesToGeoPoint"]) + reexportTypes(["GeoHash", "Coordinates", "GeoPoint"])));
|
|
345
|
+
await fs.writeFile(path15.join(runtimeDistDir, "GeoShape.ts"), await formatTs(reexportConsts(["GeoShape"]) + reexportTypes(["GeoShape"])));
|
|
346
|
+
await fs.writeFile(path15.join(runtimeDistDir, "LineString.ts"), await formatTs(reexportConsts(["LineString"]) + reexportTypes(["LineString"])));
|
|
347
|
+
await fs.writeFile(path15.join(runtimeDistDir, "MultiGeoPoint.ts"), await formatTs(reexportConsts(["MultiGeoPoint"]) + reexportTypes(["MultiGeoPoint"])));
|
|
348
|
+
await fs.writeFile(path15.join(runtimeDistDir, "MultiLineString.ts"), await formatTs(reexportConsts(["MultiLineString"]) + reexportTypes(["MultiLineString"])));
|
|
349
|
+
await fs.writeFile(path15.join(runtimeDistDir, "MultiPolygon.ts"), await formatTs(reexportConsts(["MultiPolygon"]) + reexportTypes(["MultiPolygon"])));
|
|
350
|
+
await fs.writeFile(path15.join(runtimeDistDir, "Polygon.ts"), await formatTs(reexportConsts(["Polygon"]) + reexportTypes(["LinearRing", "Polygon"])));
|
|
351
|
+
}
|
|
352
|
+
async function generateObjectSetDir(objectSetDir, fs) {
|
|
353
|
+
await fs.mkdir(objectSetDir, {
|
|
354
|
+
recursive: true
|
|
355
|
+
});
|
|
356
|
+
await fs.writeFile(path15__default.join(objectSetDir, "index.ts"), await formatTs(`
|
|
102
357
|
export * from "./ObjectSetDefinition";
|
|
103
358
|
export * from "./OntologyObjectSet";
|
|
104
|
-
`))
|
|
359
|
+
`));
|
|
360
|
+
await fs.writeFile(path15__default.join(objectSetDir, "ObjectSetDefinition.ts"), await formatTs(reexportTypes(["BaseObjectSetDefinition", "ReferenceObjectSetDefinition", "StaticObjectSetDefinition", "IntersectObjectSetDefinition", "SubtractObjectSetDefinition", "SearchAroundObjectSetDefinition", "FilterObjectSetDefinition", "ObjectSetDefinition"])));
|
|
361
|
+
await fs.writeFile(path15__default.join(objectSetDir, "OntologyObjectSet.ts"), await formatTs(reexportTypes(["OntologyObjectSet"])));
|
|
362
|
+
}
|
|
363
|
+
async function generateSharedObjectCodeDir(sharedObjectCodeDir, fs) {
|
|
364
|
+
await fs.mkdir(sharedObjectCodeDir, {
|
|
365
|
+
recursive: true
|
|
366
|
+
});
|
|
367
|
+
await fs.writeFile(path15__default.join(sharedObjectCodeDir, "index.ts"), await formatTs(`
|
|
105
368
|
export * from "./FilteredPropertiesTerminalOperations";
|
|
106
|
-
`))
|
|
369
|
+
`));
|
|
370
|
+
await fs.writeFile(path15__default.join(sharedObjectCodeDir, "FilteredPropertiesTerminalOperations.ts"), await formatTs(`import { OntologyObject } from "../OntologyObject` + reexportTypes(["FilteredPropertiesTerminalOperations", "FilteredPropertiesTerminalOperationsWithGet"], "<T extends OntologyObject, V extends Array<keyof T>>")));
|
|
371
|
+
}
|
|
372
|
+
async function generateTimeSeriesDir(timeseriesDir, fs) {
|
|
373
|
+
await fs.mkdir(timeseriesDir, {
|
|
374
|
+
recursive: true
|
|
375
|
+
});
|
|
376
|
+
await fs.writeFile(path15.join(timeseriesDir, "index.ts"), await formatTs(`
|
|
107
377
|
export * from "./TimeSeries";
|
|
108
378
|
export * from "./TimeSeriesDuration";
|
|
109
379
|
export * from "./TimeSeriesPoint";
|
|
110
|
-
|
|
380
|
+
${""}
|
|
111
381
|
export * from "./TimeSeriesQuery";
|
|
112
382
|
export * from "./TimeSeriesTerminalOperations";
|
|
113
|
-
`))
|
|
383
|
+
`));
|
|
384
|
+
await fs.writeFile(path15.join(timeseriesDir, "TimeSeries.ts"), await formatTs(reexportTypes(["TimeSeries"], `<T extends number | string>`)));
|
|
385
|
+
await fs.writeFile(path15.join(timeseriesDir, "TimeSeriesDuration.ts"), await formatTs(reexportTypes([`WhenUnit`, `DurationUnit`, `TimeSeriesDuration`])));
|
|
386
|
+
await fs.writeFile(path15.join(timeseriesDir, "TimeSeriesPoint.ts"), await formatTs(reexportTypes(["TimeSeriesPoint"], `<T extends number | string>`)));
|
|
387
|
+
await fs.writeFile(path15.join(timeseriesDir, "TimeSeriesQuery.ts"), await formatTs(reexportTypes(["TimeSeriesQuery"], `<T extends number | string>`)));
|
|
388
|
+
await fs.writeFile(path15.join(timeseriesDir, "TimeSeriesTerminalOperations.ts"), await formatTs(reexportTypes(["TimeSeriesTerminalOperations", "TimeSeriesIterator"], `<T extends number | string>`)));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/v1.1/backcompat/internal-foundry-ontology-runtime-dist/generateBaseTypesDir.ts
|
|
392
|
+
async function generateBaseTypesDir(runtimeDistDir, fs) {
|
|
393
|
+
const baseTypesDir = path15.join(runtimeDistDir, "baseTypes");
|
|
394
|
+
await fs.mkdir(baseTypesDir, {
|
|
395
|
+
recursive: true
|
|
396
|
+
});
|
|
397
|
+
await fs.writeFile(path15.join(baseTypesDir, "index.ts"), await formatTs(`export * from "./ActionType";
|
|
114
398
|
export * from "./attachments";
|
|
115
399
|
export * from "./geoshapes";
|
|
116
400
|
export * from "./links";
|
|
@@ -120,9 +404,41 @@ function B(e){return {...e,actionTypes:Object.fromEntries(Object.values(e.action
|
|
|
120
404
|
export * from "./OntologyObject";
|
|
121
405
|
export * from "./Queries";
|
|
122
406
|
export * from "./timeseries";
|
|
123
|
-
export * from "./timestamp";`));
|
|
124
|
-
|
|
125
|
-
|
|
407
|
+
export * from "./timestamp";`));
|
|
408
|
+
const geoshapesDir = path15.join(baseTypesDir, "geoshapes");
|
|
409
|
+
await generateGeoshapesDir(geoshapesDir, fs);
|
|
410
|
+
const timeseriesDir = path15.join(baseTypesDir, "timeseries");
|
|
411
|
+
await generateTimeSeriesDir(timeseriesDir, fs);
|
|
412
|
+
const attachmentsDir = path15.join(baseTypesDir, "attachments");
|
|
413
|
+
await generateAttachmentsDir(attachmentsDir, fs);
|
|
414
|
+
const objectSetDir = path15.join(baseTypesDir, "objectset");
|
|
415
|
+
await generateObjectSetDir(objectSetDir, fs);
|
|
416
|
+
const sharedObjectCodeDir = path15.join(baseTypesDir, "sharedObjectCode");
|
|
417
|
+
await generateSharedObjectCodeDir(sharedObjectCodeDir, fs);
|
|
418
|
+
await fs.writeFile(path15.join(baseTypesDir, "ActionType.ts"), await formatTs(`import { OntologyObject } from "./OntologyObject";
|
|
419
|
+
` + reexportConsts(["ActionExecutionMode", "ReturnEditsMode", "ActionValidationResult"]) + reexportTypes(["ActionExecutionOptions", "ValidationResponse", "BulkEdits"]) + reexportTypes(["CreatedObjectEdits", "ModifiedObjectEdits"], "<T extends OntologyObject>") + reexportTypes(["Edits"], "<TAddedObjects extends OntologyObject | void, TModifiedObjects extends OntologyObject | void>") + reexportTypes(["ActionResponse"], "<TEdits extends Edits<any, any> | undefined = undefined>", "<TEdits>") + reexportTypes(["ActionResponseFromOptions"], "<TOptions extends ActionExecutionOptions | undefined = undefined, TEdits extends Edits<any, any> | undefined = undefined>", "<TOptions, TEdits>")));
|
|
420
|
+
await fs.writeFile(path15.join(baseTypesDir, "OntologyObject.ts"), await formatTs(reexportTypes(["OntologyObject"]) + reexportConsts(["isOntologyObject"])));
|
|
421
|
+
await fs.writeFile(path15.join(baseTypesDir, "links.ts"), await formatTs(`import { OntologyObject } from "./OntologyObject` + reexportTypes(["SingleLink", "MultiLink"], "<T extends OntologyObject = OntologyObject>")));
|
|
422
|
+
await fs.writeFile(path15.join(baseTypesDir, "localDate.ts"), await formatTs(reexportConsts(["LocalDate"]) + reexportTypes(["LocalDate"])));
|
|
423
|
+
await fs.writeFile(path15.join(baseTypesDir, "timestamp.ts"), await formatTs(reexportConsts(["Timestamp"]) + reexportTypes(["Timestamp"])));
|
|
424
|
+
await fs.writeFile(path15.join(baseTypesDir, "Queries.ts"), await formatTs(`import { BucketValue, Range, Rangeable } from "../aggregations";
|
|
425
|
+
` + reexportTypes(["QueryResponse"], "<T>") + reexportTypes(["BaseBucket"], "<K, V>") + reexportTypes(["NestedBucket"], "<TGroupKey, TSegmentKey, TValue extends BucketValue>") + reexportTypes(["TwoDimensionalAggregation"], "<TGroupKey extends QueryBucketKey, TValue extends BucketValue = number>") + reexportTypes(["ThreeDimensionalAggregation"], "<TGroupKey extends QueryBucketKey, TSegmentKey extends QueryBucketKey, TValue extends BucketValue = number>") + reexportTypes(["QueryBucketKey"])));
|
|
426
|
+
await fs.writeFile(path15.join(baseTypesDir, "ObjectType.ts"), await formatTs(`import { OntologyObject } from "./OntologyObject";` + reexportTypes(["BaseType", "StringType", "IntegerType", "DateType", "BooleanType", "ByteType", "DecimalType", "FloatType", "TimestampType", "ShortType", "LongType", "DoubleType", "GeoPointType", "GeoShapeType", "AttachmentType", "ObjectType", "StructField", "QueryBucketRangeableType", "QueryBucketKeyType", "QueryBucketValueType", "AllValueTypes", "OntologyType", "ObjectTypeProperties", "StructType"]) + reexportTypes(["TimeSeriesType", "ArrayType", "SetType"], "<T extends BaseType>") + reexportTypes(["Property"], "<TType extends OntologyType = OntologyType>") + reexportTypes(["BaseObjectType"], "<TOntologyObject extends OntologyObject = OntologyObject>") + reexportTypes(["ObjectSetType"], "<T extends ObjectType>") + reexportTypes(["RangeType"], "<T extends QueryBucketRangeableType>") + reexportTypes(["TwoDimensionalAggregationType"], "<TGroupKey extends QueryBucketKeyType, TValue extends QueryBucketValueType>") + reexportTypes(["ThreeDimensionalAggregationType"], "<TGroupKey extends QueryBucketKeyType, TSegmentKey extends QueryBucketKeyType, TValue extends QueryBucketValueType>")));
|
|
427
|
+
}
|
|
428
|
+
async function generateClientDir(runtimeDistDir, fs) {
|
|
429
|
+
const pagingDir = path15__default.join(runtimeDistDir, "client");
|
|
430
|
+
await fs.mkdir(pagingDir, {
|
|
431
|
+
recursive: true
|
|
432
|
+
});
|
|
433
|
+
await fs.writeFile(path15__default.join(pagingDir, "index.ts"), await formatTs(`export * from "./clientOptions";`));
|
|
434
|
+
await fs.writeFile(path15__default.join(pagingDir, "clientOptions.ts"), await formatTs(`import {Auth} from "@osdk/legacy-client";` + reexportTypes(["FoundryClientOptions"], "<TAuth extends Auth = Auth>")));
|
|
435
|
+
}
|
|
436
|
+
async function generateFiltersDir(runtimeDistDir, fs) {
|
|
437
|
+
const pagingDir = path15__default.join(runtimeDistDir, "filters");
|
|
438
|
+
await fs.mkdir(pagingDir, {
|
|
439
|
+
recursive: true
|
|
440
|
+
});
|
|
441
|
+
await fs.writeFile(path15__default.join(pagingDir, "index.ts"), await formatTs(`export * from "./ArrayFilter";
|
|
126
442
|
export * from "./AttachmentFilter";
|
|
127
443
|
export * from "./BooleanFilter";
|
|
128
444
|
export * from "./DateTimeFilters";
|
|
@@ -132,28 +448,96 @@ function B(e){return {...e,actionTypes:Object.fromEntries(Object.values(e.action
|
|
|
132
448
|
export * from "./NumericFilter";
|
|
133
449
|
export * from "./Op";
|
|
134
450
|
export * from "./OrderByOption";
|
|
135
|
-
export * from "./StringFilter";`))
|
|
136
|
-
|
|
137
|
-
|
|
451
|
+
export * from "./StringFilter";`));
|
|
452
|
+
await fs.writeFile(path15__default.join(pagingDir, "ArrayFilter.ts"), await formatTs(`import { Attachment, GeoPoint, GeoShape, LocalDate, Timestamp } from "../baseTypes";` + reexportConsts(["ArrayFilter"]) + reexportTypes(["ArrayFilter"], "<T extends string | number | Timestamp | LocalDate | boolean | GeoShape | GeoPoint | Attachment>")));
|
|
453
|
+
await fs.writeFile(path15__default.join(pagingDir, "AttachmentFilter.ts"), await formatTs(reexportConsts(["AttachmentFilter"]) + reexportTypes(["AttachmentFilter"])));
|
|
454
|
+
await fs.writeFile(path15__default.join(pagingDir, "BooleanFilter.ts"), await formatTs(reexportConsts(["BooleanFilter"]) + reexportTypes(["BooleanFilter"])));
|
|
455
|
+
await fs.writeFile(path15__default.join(pagingDir, "GeoPointFilter.ts"), await formatTs(reexportConsts(["GeoPointFilter"]) + reexportTypes(["GeoPointFilter", "BoundingBox"])));
|
|
456
|
+
await fs.writeFile(path15__default.join(pagingDir, "DateTimeFilters.ts"), await formatTs(reexportConsts(["TimestampFilter", "LocalDateFilter"]) + reexportTypes(["TimestampFilter", "LocalDateFilter"])));
|
|
457
|
+
await fs.writeFile(path15__default.join(pagingDir, "GeoShapeFilter.ts"), await formatTs(reexportConsts(["GeoShapeFilter"]) + reexportTypes(["GeoShapeFilter"])));
|
|
458
|
+
await fs.writeFile(path15__default.join(pagingDir, "NumericFilter.ts"), await formatTs(reexportConsts(["NumericFilter"]) + reexportTypes(["NumericFilter"])));
|
|
459
|
+
await fs.writeFile(path15__default.join(pagingDir, "Op.ts"), await formatTs(reexportConsts(["Op"])));
|
|
460
|
+
await fs.writeFile(path15__default.join(pagingDir, "OrderByOption.ts"), await formatTs(reexportConsts(["OrderByOption"]) + reexportTypes(["OrderByOption"])));
|
|
461
|
+
await fs.writeFile(path15__default.join(pagingDir, "StringFilter.ts"), await formatTs(reexportConsts(["StringFilter"]) + reexportTypes(["StringFilter"])));
|
|
462
|
+
await fs.writeFile(path15__default.join(pagingDir, "Filters.ts"), await formatTs(`import { OntologyObject } from "@osdk/legacy-client";` + reexportTypes(["ObjectTypeFilterFunction", "ObjectTypeOrderByFunction"], "<T extends OntologyObject>") + reexportTypes(["BoundingBoxFilter", "DistanceOf", "SearchClause", "LtWhereClause", "GtWhereClause", "LteWhereClause", "GteWhereClause", "EqWhereClause", "IsNullWhereClause", "ContainsWhereClause", "StartsWithWhereClause", "ContainsAllTermsInOrderWhereClause", "ContainsAnyTermWhereClause", "ContainsAllTermsWhereClause", "WithinDistanceOfWhereClause", "WithinBoundingBoxWhereClause", "IntersectsBoundingBoxWhereClause", "DoesNotIntersectBoundingBoxWhereClause", "WithinPolygonWhereClause", "IntersectsPolygonWhereClause", "DoesNotIntersectPolygonWhereClause", "AndWhereClause", "OrWhereClause", "NotWhereClause", "WhereClause", "OrderByClause"]) + reexportTypes(["FilterType"], "<T extends string | number>")));
|
|
463
|
+
}
|
|
464
|
+
async function generateErrors(fs, ontologyProviderDir) {
|
|
465
|
+
await fs.writeFile(path15.join(ontologyProviderDir, "Errors.ts"), await formatTs(reexportTypes(["PermissionDenied", "Unauthorized", "InvalidAggregationRangeValue", "MalformedPropertyFilters", "PropertiesNotFilterable", "ParametersNotFound", "ApplyActionFailed", "PropertyTypesSearchNotSupported", "InvalidParameterValue", "QueryTimeExceededLimit", "CompositePrimaryKeyNotSupported", "PropertyBaseTypeNotSupported", "PropertiesNotSearchable", "AttachmentNotFound", "ObjectTypeNotFound", "InvalidGroupId", "OntologySyncing", "ActionNotFound", "ParameterObjectSetRidNotFound", "LinkTypeNotFound", "InvalidRangeQuery", "ActionParameterObjectNotFound", "InvalidPropertyValue", "PropertiesNotSortable", "FunctionExecutionTimedOut", "InvalidFields", "ActionTypeNotFound", "ObjectTypeNotSynced", "OntologyEditsExceededLimit", "AggregationGroupCountExceededLimit", "InvalidContentType", "PropertiesNotFound", "FunctionInvalidInput", "InvalidSortOrder", "QueryDepthExceededLimit", "InvalidPropertyFiltersCombination", "ObjectsExceededLimit", "DuplicateOrderBy", "FunctionEncounteredUserFacingError", "InvalidUserId", "QueryNotFound", "InvalidAggregationRange", "ParameterObjectNotFound", "QueryMemoryExceededLimit", "InvalidContentLength", "OntologyNotFound", "ActionParameterObjectTypeNotFound", "UnknownParameter", "InvalidSortType", "PropertyFiltersNotSupported", "ActionValidationFailed", "MultipleGroupByOnFieldNotSupported", "LinkedObjectNotFound", "ActionEditedPropertiesNotFound", "InvalidPropertyFilterValue", "QueryEncounteredUserFacingError", "AttachmentSizeExceededLimit", "ObjectNotFound", "PropertyApiNameNotFound", "ParameterTypeNotSupported", "InvalidAggregationRangePropertyType", "MissingParameter"])));
|
|
466
|
+
}
|
|
467
|
+
async function generateOntologyMetadata(fs, ontologyProviderDir) {
|
|
468
|
+
await fs.writeFile(path15.join(ontologyProviderDir, "OntologyMetadata.ts"), await formatTs(reexportTypes(["OntologyMetadata"])));
|
|
469
|
+
}
|
|
470
|
+
async function generateResult(fs, ontologyProviderDir) {
|
|
471
|
+
await fs.writeFile(path15.join(ontologyProviderDir, "Result.ts"), await formatTs(`import {FoundryApiError} from "@osdk/legacy-client";
|
|
472
|
+
` + reexportTypes(["Ok", "Err"], "<T>") + reexportTypes(["Result"], "<V, E = FoundryApiError>", "<V,E>") + reexportConsts(["isOk", "isErr", "visitError"]) + reexportTypes(["ErrorVisitor"], "<E extends FoundryApiError, R>", "<E,R>") + reexportTypes(["ExtractKeysWithType"], "<T, K extends keyof T>", "<T,K>")));
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// src/v1.1/backcompat/internal-foundry-ontology-runtime-dist/generateOntologyProviderDir.ts
|
|
476
|
+
async function generateOntologyProviderDir(fs, runtimeDistDir) {
|
|
477
|
+
const ontologyProviderDir = path15.join(runtimeDistDir, "ontologyProvider");
|
|
478
|
+
await fs.mkdir(ontologyProviderDir, {
|
|
479
|
+
recursive: true
|
|
480
|
+
});
|
|
481
|
+
await generateErrors(fs, ontologyProviderDir);
|
|
482
|
+
await generateOntologyMetadata(fs, ontologyProviderDir);
|
|
483
|
+
await generateResult(fs, ontologyProviderDir);
|
|
484
|
+
await fs.writeFile(path15.join(ontologyProviderDir, "index.ts"), await formatTs(`
|
|
485
|
+
${""}
|
|
138
486
|
export * from "./Errors";
|
|
139
487
|
export * from "./OntologyMetadata";
|
|
140
|
-
|
|
141
|
-
|
|
488
|
+
${""}
|
|
489
|
+
${""}
|
|
142
490
|
// export * from "./Result";
|
|
143
|
-
`));
|
|
491
|
+
`));
|
|
492
|
+
}
|
|
493
|
+
async function generatePagingDir(runtimeDistDir, fs) {
|
|
494
|
+
const pagingDir = path15.join(runtimeDistDir, "paging");
|
|
495
|
+
await fs.mkdir(pagingDir, {
|
|
496
|
+
recursive: true
|
|
497
|
+
});
|
|
498
|
+
await fs.writeFile(path15.join(pagingDir, "index.ts"), await formatTs(`export * from "./Page";`));
|
|
499
|
+
await fs.writeFile(path15.join(pagingDir, "Page.ts"), await formatTs(reexportTypes(["Page"], "<T>")));
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// src/v1.1/backcompat/generateOntologyRuntimeDistDir.ts
|
|
503
|
+
async function generateOntologyRuntimeDistDir(outDir, fs) {
|
|
504
|
+
const runtimeDistDir = path15.join(outDir, "internal", "@foundry", "ontology-runtime", "dist");
|
|
505
|
+
await fs.mkdir(runtimeDistDir, {
|
|
506
|
+
recursive: true
|
|
507
|
+
});
|
|
508
|
+
await generateOntologyProviderDir(fs, runtimeDistDir);
|
|
509
|
+
await generateAggregationsDir(fs, runtimeDistDir);
|
|
510
|
+
await generatePagingDir(runtimeDistDir, fs);
|
|
511
|
+
await generateBaseTypesDir(runtimeDistDir, fs);
|
|
512
|
+
await generateClientDir(runtimeDistDir, fs);
|
|
513
|
+
await generateFiltersDir(runtimeDistDir, fs);
|
|
514
|
+
await fs.writeFile(
|
|
515
|
+
path15.join(runtimeDistDir, "index.ts"),
|
|
516
|
+
// TRASHFIXME
|
|
517
|
+
await formatTs(`
|
|
144
518
|
export * from "./aggregations";
|
|
145
519
|
export * from "./baseTypes";
|
|
146
|
-
|
|
520
|
+
${""}
|
|
147
521
|
// export * from "./filters";
|
|
148
|
-
|
|
149
|
-
|
|
522
|
+
${""}
|
|
523
|
+
${""}
|
|
150
524
|
|
|
151
525
|
export * from "./ontologyProvider";
|
|
152
526
|
export * from "./paging";
|
|
153
|
-
`)
|
|
527
|
+
`)
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// src/v1.1/generateBackCompatDeprecatedExports.ts
|
|
532
|
+
async function generateBackCompatDeprecatedExports(fs, outDir) {
|
|
533
|
+
await generateOntologyRuntimeDistDir(outDir, fs);
|
|
534
|
+
await generateOAuthClientDistDir(outDir, fs);
|
|
535
|
+
}
|
|
536
|
+
async function generateFoundryClientFile(fs, outDir, importExt = "") {
|
|
537
|
+
await fs.writeFile(path15__default.join(outDir, "FoundryClient.ts"), await formatTs(`
|
|
154
538
|
import { BaseFoundryClient } from "@osdk/legacy-client";
|
|
155
539
|
import type { Auth, FoundryClientOptions } from "@osdk/legacy-client";
|
|
156
|
-
import { Ontology } from "./Ontology${
|
|
540
|
+
import { Ontology } from "./Ontology${importExt}";
|
|
157
541
|
|
|
158
542
|
export class FoundryClient<TAuth extends Auth = Auth> extends BaseFoundryClient<typeof Ontology, TAuth> {
|
|
159
543
|
constructor(options: FoundryClientOptions<TAuth>) {
|
|
@@ -163,199 +547,1043 @@ function B(e){return {...e,actionTypes:Object.fromEntries(Object.values(e.action
|
|
|
163
547
|
get ontology(): Ontology {
|
|
164
548
|
return super.ontology;
|
|
165
549
|
}
|
|
166
|
-
}`));
|
|
550
|
+
}`));
|
|
551
|
+
}
|
|
552
|
+
async function generateIndexFile(fs, outDir, importExt) {
|
|
553
|
+
await fs.mkdir(outDir, {
|
|
554
|
+
recursive: true
|
|
555
|
+
});
|
|
556
|
+
await fs.writeFile(path15.join(outDir, "index.ts"), await formatTs(`
|
|
167
557
|
export * from "@osdk/legacy-client";
|
|
168
|
-
export type { Ontology } from "./Ontology${
|
|
169
|
-
export { FoundryClient } from "./FoundryClient${
|
|
170
|
-
`));
|
|
558
|
+
export type { Ontology } from "./Ontology${importExt}";
|
|
559
|
+
export { FoundryClient } from "./FoundryClient${importExt}";
|
|
560
|
+
`));
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// src/util/commaSeparatedIdentifiers.ts
|
|
564
|
+
function commaSeparatedIdentifiers(identifiers, alternateNames) {
|
|
565
|
+
return identifiers.map((i) => {
|
|
566
|
+
const alt = alternateNames?.get(i);
|
|
567
|
+
if (alt) {
|
|
568
|
+
return `${i}: ${alt}`;
|
|
569
|
+
}
|
|
570
|
+
return i;
|
|
571
|
+
}).join(",");
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// src/util/commaSeparatedTypeIdentifiers.ts
|
|
575
|
+
function commaSeparatedTypeIdentifiers(identifiers, altNames) {
|
|
576
|
+
return identifiers.map((i) => `${i}: typeof ${altNames?.get(i) ?? i}`).join(",");
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// src/v1.1/generateMetadataFile.ts
|
|
580
|
+
async function generateMetadataFile(ontology, fs, outDir, importExt = "") {
|
|
581
|
+
const objectNames = Object.keys(ontology.objectTypes);
|
|
582
|
+
const actionNames = Object.keys(ontology.actionTypes);
|
|
583
|
+
const queryNames = Object.keys(ontology.queryTypes);
|
|
584
|
+
const actionAltNames = /* @__PURE__ */ new Map();
|
|
585
|
+
const queryAltNames = /* @__PURE__ */ new Map();
|
|
586
|
+
const seenIdentifiers = new Set(objectNames);
|
|
587
|
+
for (const actionName of actionNames) {
|
|
588
|
+
if (seenIdentifiers.has(actionName)) {
|
|
589
|
+
actionAltNames.set(actionName, `${actionName}Action`);
|
|
590
|
+
} else {
|
|
591
|
+
seenIdentifiers.add(actionName);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
for (const queryName of queryNames) {
|
|
595
|
+
if (seenIdentifiers.has(queryName)) {
|
|
596
|
+
queryAltNames.set(queryName, `${queryName}Query`);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
const getImportClause = (name, altNames) => {
|
|
600
|
+
const alt = altNames.get(name);
|
|
601
|
+
if (alt) {
|
|
602
|
+
return `${name} as ${alt}`;
|
|
603
|
+
} else {
|
|
604
|
+
return name;
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
await fs.writeFile(path15__default.join(outDir, "Ontology.ts"), await formatTs(`
|
|
171
608
|
import type { OntologyDefinition } from "@osdk/api";
|
|
172
609
|
import type { Ontology as ClientOntology } from "@osdk/legacy-client";
|
|
173
|
-
import type { Objects } from "./ontology/objects/Objects${
|
|
174
|
-
import type { Actions } from "./ontology/actions/Actions${
|
|
175
|
-
import type { Queries } from "./ontology/queries/Queries${
|
|
176
|
-
${
|
|
177
|
-
`)}
|
|
178
|
-
${
|
|
179
|
-
`)}
|
|
180
|
-
${c.map(p=>`import {${w(p,u)}} from "./ontology/queries/${p}${n}";`).join(`
|
|
181
|
-
`)}
|
|
610
|
+
import type { Objects } from "./ontology/objects/Objects${importExt}";
|
|
611
|
+
import type { Actions } from "./ontology/actions/Actions${importExt}";
|
|
612
|
+
import type { Queries } from "./ontology/queries/Queries${importExt}";
|
|
613
|
+
${objectNames.map((name) => `import {${name}} from "./ontology/objects/${name}${importExt}";`).join("\n")}
|
|
614
|
+
${actionNames.map((name) => `import {${getImportClause(name, actionAltNames)}} from "./ontology/actions/${name}${importExt}";`).join("\n")}
|
|
615
|
+
${queryNames.map((name) => `import {${getImportClause(name, queryAltNames)}} from "./ontology/queries/${name}${importExt}";`).join("\n")}
|
|
182
616
|
|
|
183
617
|
export const Ontology : {
|
|
184
618
|
metadata: {
|
|
185
|
-
ontologyRid: "${
|
|
186
|
-
ontologyApiName: "${
|
|
619
|
+
ontologyRid: "${ontology.ontology.rid}",
|
|
620
|
+
ontologyApiName: "${ontology.ontology.apiName}",
|
|
187
621
|
userAgent: "foundry-typescript-osdk/0.0.1",
|
|
188
622
|
},
|
|
189
623
|
objects: {
|
|
190
|
-
${
|
|
624
|
+
${commaSeparatedTypeIdentifiers(objectNames)}
|
|
191
625
|
},
|
|
192
626
|
actions: {
|
|
193
|
-
${
|
|
627
|
+
${commaSeparatedTypeIdentifiers(actionNames, actionAltNames)}
|
|
194
628
|
},
|
|
195
629
|
queries: {
|
|
196
|
-
${
|
|
630
|
+
${commaSeparatedTypeIdentifiers(queryNames, queryAltNames)}
|
|
197
631
|
},
|
|
198
632
|
} = {
|
|
199
633
|
metadata: {
|
|
200
|
-
ontologyRid: "${
|
|
201
|
-
ontologyApiName: "${
|
|
634
|
+
ontologyRid: "${ontology.ontology.rid}" as const,
|
|
635
|
+
ontologyApiName: "${ontology.ontology.apiName}" as const,
|
|
202
636
|
userAgent: "foundry-typescript-osdk/0.0.1" as const,
|
|
203
637
|
},
|
|
204
638
|
objects: {
|
|
205
|
-
${
|
|
639
|
+
${commaSeparatedIdentifiers(objectNames)}
|
|
206
640
|
},
|
|
207
641
|
actions: {
|
|
208
|
-
${
|
|
642
|
+
${commaSeparatedIdentifiers(actionNames, actionAltNames)}
|
|
209
643
|
},
|
|
210
644
|
queries: {
|
|
211
|
-
${
|
|
645
|
+
${commaSeparatedIdentifiers(queryNames, queryAltNames)}
|
|
212
646
|
}
|
|
213
|
-
} satisfies OntologyDefinition
|
|
647
|
+
} satisfies OntologyDefinition<
|
|
648
|
+
${stringUnionFrom(objectNames)},
|
|
649
|
+
${stringUnionFrom(Object.values(ontology.actionTypes).map((actionType) => actionType.apiName))},
|
|
650
|
+
${stringUnionFrom(Object.values(ontology.queryTypes).map((queryType) => queryType.apiName))}>;
|
|
214
651
|
|
|
215
652
|
export interface Ontology extends ClientOntology<typeof Ontology> {
|
|
216
653
|
objects: Objects;
|
|
217
654
|
actions: Actions;
|
|
218
655
|
queries: Queries;
|
|
219
|
-
}`));
|
|
656
|
+
}`));
|
|
657
|
+
}
|
|
658
|
+
function stringUnionFrom(values) {
|
|
659
|
+
if (values.length === 0) {
|
|
660
|
+
return "never";
|
|
661
|
+
}
|
|
662
|
+
return values.map((n) => `"${n}"`).join("|");
|
|
663
|
+
}
|
|
664
|
+
async function generateObjectsInterfaceFile(ontology, fs, outDir, importExt = "") {
|
|
665
|
+
await fs.mkdir(outDir, {
|
|
666
|
+
recursive: true
|
|
667
|
+
});
|
|
668
|
+
await fs.writeFile(path15__default.join(outDir, "Objects.ts"), await formatTs(`
|
|
220
669
|
import { BaseObjectSet } from "@osdk/legacy-client";
|
|
221
|
-
${Array.from(Object.keys(
|
|
222
|
-
`)}
|
|
670
|
+
${Array.from(Object.keys(ontology.objectTypes)).map((importedObject) => `import type { ${importedObject} } from "./${importedObject}${importExt}";`).join("\n")}
|
|
223
671
|
|
|
224
672
|
export interface Objects {
|
|
225
|
-
${Object.keys(
|
|
226
|
-
|
|
673
|
+
${Object.keys(ontology.objectTypes).map((apiName) => `${apiName} : BaseObjectSet<${apiName}>;`).join("\n")}
|
|
674
|
+
}
|
|
675
|
+
;`));
|
|
676
|
+
}
|
|
677
|
+
async function generateObjectsInterfaceSupportFiles(ontology, fs, outDir, importExt = "") {
|
|
678
|
+
await fs.mkdir(outDir, {
|
|
679
|
+
recursive: true
|
|
680
|
+
});
|
|
681
|
+
for (const {
|
|
682
|
+
objectType: {
|
|
683
|
+
apiName
|
|
227
684
|
}
|
|
228
|
-
|
|
685
|
+
} of Object.values(ontology.objectTypes)) {
|
|
686
|
+
const fileName = join(outDir, `${apiName}.ts`);
|
|
687
|
+
const localApiName = `OG_${apiName}`;
|
|
688
|
+
const contents = [];
|
|
689
|
+
contents.push(`import { ObjectSetAggregateArg, ObjectSetFilterArg, ObjectSetGroupByArg, ObjectSetMultipleAggregateArg, ObjectSetOrderByArg } from "@osdk/legacy-client";`);
|
|
690
|
+
contents.push(`import { ${apiName} as ${localApiName} } from "../${apiName}${importExt}";`);
|
|
691
|
+
contents.push("");
|
|
692
|
+
contents.push(`/** @deprecated Use ${apiName} from ontology/objects instead */`, `export type ${apiName} = ${localApiName};`);
|
|
693
|
+
contents.push(`/** @deprecated Use ObjectSetFilterArg<${apiName}> instead */`, `export type ${apiName}Filter = ObjectSetFilterArg<${localApiName}>;`);
|
|
694
|
+
contents.push(`/** @deprecated Use ObjectSetOrderByArg<${apiName}> instead */`, `export type ${apiName}OrderBy = ObjectSetOrderByArg<${localApiName}>;`);
|
|
695
|
+
contents.push(`/** @deprecated Use ObjectSetGroupByArg<${apiName}> instead */`, `export type ${apiName}GroupByProperties = ObjectSetGroupByArg<${localApiName}>;`);
|
|
696
|
+
contents.push(`
|
|
229
697
|
/**
|
|
230
|
-
* Aggregation properties for ${
|
|
231
|
-
* @deprecated Use ObjectSetAggregateArg<${
|
|
232
|
-
|
|
698
|
+
* Aggregation properties for ${apiName}
|
|
699
|
+
* @deprecated Use ObjectSetAggregateArg<${apiName}> instead
|
|
700
|
+
*/`, `export type ${apiName}AggregationProperties = ObjectSetAggregateArg<${localApiName}>;`);
|
|
701
|
+
contents.push(`
|
|
233
702
|
/**
|
|
234
|
-
* Multiple aggregation properties for ${
|
|
235
|
-
* @deprecated Use ObjectSetMultipleAggregateArg<${
|
|
236
|
-
|
|
237
|
-
|
|
703
|
+
* Multiple aggregation properties for ${apiName}.
|
|
704
|
+
* @deprecated Use ObjectSetMultipleAggregateArg<${apiName}> instead
|
|
705
|
+
*/`, `export type ${apiName}MultipleAggregationProperties = ObjectSetMultipleAggregateArg<${localApiName}>;`);
|
|
706
|
+
await fs.writeFile(fileName, contents.join("\n"));
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
async function generateOntologyIndexFile(fs, outDir) {
|
|
710
|
+
await fs.mkdir(outDir, {
|
|
711
|
+
recursive: true
|
|
712
|
+
});
|
|
713
|
+
await fs.writeFile(path15.join(outDir, "index.ts"), await formatTs(`
|
|
238
714
|
export type { ObjectSet } from "@osdk/legacy-client";
|
|
239
|
-
`));
|
|
715
|
+
`));
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// src/shared/wireActionTypeV2ToSdkActionDefinition.ts
|
|
719
|
+
function wireActionTypeV2ToSdkActionDefinition(input) {
|
|
720
|
+
const modifiedEntityTypes = getModifiedEntityTypes(input);
|
|
721
|
+
return {
|
|
722
|
+
apiName: input.apiName,
|
|
723
|
+
parameters: Object.fromEntries(Object.entries(input.parameters).map(([key, value]) => [key, wireActionParameterV2ToSdkParameterDefinition(value)])),
|
|
724
|
+
displayName: input.displayName,
|
|
725
|
+
description: input.description,
|
|
726
|
+
modifiedEntities: createModifiedEntities(modifiedEntityTypes.addedObjects, modifiedEntityTypes.modifiedObjects)
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
function wireActionParameterV2ToSdkParameterDefinition(value) {
|
|
730
|
+
switch (value.dataType.type) {
|
|
731
|
+
case "string":
|
|
732
|
+
case "boolean":
|
|
733
|
+
case "object":
|
|
734
|
+
case "attachment":
|
|
735
|
+
case "date":
|
|
736
|
+
case "double":
|
|
737
|
+
case "integer":
|
|
738
|
+
case "long":
|
|
739
|
+
case "objectSet":
|
|
740
|
+
case "timestamp":
|
|
741
|
+
return {
|
|
742
|
+
multiplicity: false,
|
|
743
|
+
type: actionPropertyToSdkPropertyDefinition(value.dataType),
|
|
744
|
+
nullable: value.required ? false : true,
|
|
745
|
+
description: value.description
|
|
746
|
+
};
|
|
747
|
+
case "array":
|
|
748
|
+
return {
|
|
749
|
+
multiplicity: true,
|
|
750
|
+
type: actionPropertyToSdkPropertyDefinition(value.dataType),
|
|
751
|
+
nullable: value.required ? false : true,
|
|
752
|
+
description: value.description
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
function actionPropertyToSdkPropertyDefinition(parameterType) {
|
|
757
|
+
switch (parameterType.type) {
|
|
758
|
+
case "string":
|
|
759
|
+
case "boolean":
|
|
760
|
+
case "attachment":
|
|
761
|
+
case "double":
|
|
762
|
+
case "integer":
|
|
763
|
+
case "long":
|
|
764
|
+
case "timestamp":
|
|
765
|
+
return parameterType.type;
|
|
766
|
+
case "date":
|
|
767
|
+
return "datetime";
|
|
768
|
+
case "objectSet":
|
|
769
|
+
return {
|
|
770
|
+
type: "objectSet",
|
|
771
|
+
objectSet: parameterType.objectTypeApiName
|
|
772
|
+
};
|
|
773
|
+
case "object":
|
|
774
|
+
return {
|
|
775
|
+
type: "object",
|
|
776
|
+
object: parameterType.objectTypeApiName
|
|
777
|
+
};
|
|
778
|
+
case "array":
|
|
779
|
+
return actionPropertyToSdkPropertyDefinition(parameterType.subType);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function createModifiedEntities(addedObjects, modifiedObjects) {
|
|
783
|
+
let entities = {};
|
|
784
|
+
for (const key of addedObjects) {
|
|
785
|
+
entities[key] = {
|
|
786
|
+
created: true,
|
|
787
|
+
modified: false
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
for (const key of modifiedObjects) {
|
|
791
|
+
if (entities[key]) {
|
|
792
|
+
entities[key].modified = true;
|
|
793
|
+
} else {
|
|
794
|
+
entities[key] = {
|
|
795
|
+
created: false,
|
|
796
|
+
modified: true
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return entities;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// src/v1.1/generatePerActionDataFiles.ts
|
|
804
|
+
async function generatePerActionDataFiles(ontology, fs, outDir, importExt = "") {
|
|
805
|
+
await fs.mkdir(outDir, {
|
|
806
|
+
recursive: true
|
|
807
|
+
});
|
|
808
|
+
await Promise.all(Object.values(ontology.actionTypes).map(async (action) => {
|
|
809
|
+
const uniqueApiNames = new Set(extractReferencedObjectsFromAction(action));
|
|
810
|
+
await fs.writeFile(path15__default.join(outDir, `${action.apiName}.ts`), await formatTs(`
|
|
240
811
|
import { ActionDefinition } from "@osdk/api";
|
|
241
812
|
|
|
242
|
-
export const ${
|
|
243
|
-
|
|
244
|
-
`)
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
813
|
+
export const ${action.apiName} = ${JSON.stringify(wireActionTypeV2ToSdkActionDefinition(action), null, 2)} satisfies ActionDefinition<"${action.apiName}", ${uniqueApiNames.size > 0 ? [...uniqueApiNames].map((apiName) => `"${apiName}"`).join("|") : "never"}>;`));
|
|
814
|
+
}));
|
|
815
|
+
await fs.writeFile(path15__default.join(outDir, `index.ts`), await formatTs(`
|
|
816
|
+
${Object.values(ontology.actionTypes).map((action) => `export * from "./${action.apiName}${importExt}";`).join("\n")}
|
|
817
|
+
`));
|
|
818
|
+
}
|
|
819
|
+
function extractReferencedObjectsFromAction(actionType) {
|
|
820
|
+
const referencedObjectsInParameters = Object.values(actionType.parameters).flatMap(({
|
|
821
|
+
dataType
|
|
822
|
+
}) => {
|
|
823
|
+
const objectTypeReference = extractReferencedObjectsFromActionParameter(dataType);
|
|
824
|
+
return objectTypeReference ? [objectTypeReference] : [];
|
|
825
|
+
});
|
|
826
|
+
const referenceObjectsInEdits = actionType.operations.flatMap((value) => {
|
|
827
|
+
switch (value.type) {
|
|
828
|
+
case "createObject":
|
|
829
|
+
return [value.objectTypeApiName];
|
|
830
|
+
case "modifyObject":
|
|
831
|
+
return [value.objectTypeApiName];
|
|
832
|
+
case "deleteObject":
|
|
833
|
+
case "createLink":
|
|
834
|
+
case "deleteLink":
|
|
835
|
+
return [];
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
return [...referenceObjectsInEdits, ...referencedObjectsInParameters];
|
|
839
|
+
}
|
|
840
|
+
function extractReferencedObjectsFromActionParameter(actionParameter) {
|
|
841
|
+
switch (actionParameter.type) {
|
|
842
|
+
case "objectSet":
|
|
843
|
+
case "object":
|
|
844
|
+
return actionParameter.objectTypeApiName;
|
|
845
|
+
case "array":
|
|
846
|
+
return extractReferencedObjectsFromActionParameter(actionParameter.subType);
|
|
847
|
+
case "string":
|
|
848
|
+
case "boolean":
|
|
849
|
+
case "attachment":
|
|
850
|
+
case "date":
|
|
851
|
+
case "double":
|
|
852
|
+
case "integer":
|
|
853
|
+
case "long":
|
|
854
|
+
case "timestamp":
|
|
855
|
+
return void 0;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// src/shared/wirePropertyV2ToSdkPrimaryKeyTypeDefinition.ts
|
|
860
|
+
function wirePropertyV2ToSdkPrimaryKeyTypeDefinition(input) {
|
|
861
|
+
switch (input.dataType.type) {
|
|
862
|
+
case "integer":
|
|
863
|
+
case "double":
|
|
864
|
+
case "string":
|
|
865
|
+
case "boolean":
|
|
866
|
+
case "attachment":
|
|
867
|
+
case "byte":
|
|
868
|
+
case "decimal":
|
|
869
|
+
case "float":
|
|
870
|
+
case "geopoint":
|
|
871
|
+
case "geoshape":
|
|
872
|
+
case "long":
|
|
873
|
+
case "short": {
|
|
874
|
+
return input.dataType.type;
|
|
875
|
+
}
|
|
876
|
+
case "date": {
|
|
877
|
+
return "datetime";
|
|
878
|
+
}
|
|
879
|
+
case "timestamp": {
|
|
880
|
+
return "timestamp";
|
|
881
|
+
}
|
|
882
|
+
case "timeseries":
|
|
883
|
+
case "array":
|
|
884
|
+
throw new Error(`Type not supported for primaryKey: ${input.dataType.type}`);
|
|
885
|
+
default:
|
|
886
|
+
input.dataType;
|
|
887
|
+
throw new Error(`Unknown type encountered for primaryKey: ${input.dataType}`);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// src/shared/wirePropertyV2ToSdkPropertyDefinition.ts
|
|
892
|
+
function wirePropertyV2ToSdkPropertyDefinition(input, isNullable = true) {
|
|
893
|
+
switch (input.dataType.type) {
|
|
894
|
+
case "integer":
|
|
895
|
+
case "string":
|
|
896
|
+
case "byte":
|
|
897
|
+
case "decimal":
|
|
898
|
+
case "double":
|
|
899
|
+
case "float":
|
|
900
|
+
case "long":
|
|
901
|
+
case "short":
|
|
902
|
+
case "boolean":
|
|
903
|
+
case "date":
|
|
904
|
+
case "attachment":
|
|
905
|
+
case "geopoint":
|
|
906
|
+
case "geoshape":
|
|
907
|
+
case "timestamp":
|
|
908
|
+
case "timeseries":
|
|
909
|
+
return {
|
|
910
|
+
multiplicity: false,
|
|
911
|
+
description: input.description,
|
|
912
|
+
type: objectPropertyTypeToSdkPropertyDefinition(input.dataType),
|
|
913
|
+
nullable: isNullable
|
|
914
|
+
};
|
|
915
|
+
case "array": {
|
|
916
|
+
return {
|
|
917
|
+
multiplicity: true,
|
|
918
|
+
description: input.description,
|
|
919
|
+
type: objectPropertyTypeToSdkPropertyDefinition(input.dataType),
|
|
920
|
+
nullable: true
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
default:
|
|
924
|
+
input.dataType;
|
|
925
|
+
throw new Error(`Unexpected data type ${JSON.stringify(input.dataType)}`);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
function objectPropertyTypeToSdkPropertyDefinition(propertyType) {
|
|
929
|
+
switch (propertyType.type) {
|
|
930
|
+
case "integer":
|
|
931
|
+
case "string":
|
|
932
|
+
case "byte":
|
|
933
|
+
case "decimal":
|
|
934
|
+
case "double":
|
|
935
|
+
case "float":
|
|
936
|
+
case "long":
|
|
937
|
+
case "short":
|
|
938
|
+
case "boolean":
|
|
939
|
+
case "attachment":
|
|
940
|
+
case "geopoint":
|
|
941
|
+
case "geoshape":
|
|
942
|
+
case "timestamp":
|
|
943
|
+
return propertyType.type;
|
|
944
|
+
case "date":
|
|
945
|
+
return "datetime";
|
|
946
|
+
case "array":
|
|
947
|
+
return objectPropertyTypeToSdkPropertyDefinition(propertyType.subType);
|
|
948
|
+
case "timeseries":
|
|
949
|
+
if (propertyType.itemType.type === "string") {
|
|
950
|
+
return "stringTimeseries";
|
|
951
|
+
}
|
|
952
|
+
return "numericTimeseries";
|
|
953
|
+
default:
|
|
954
|
+
throw new Error(`Unexecpected data type ${propertyType}`);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
// src/shared/wireObjectTypeV2ToSdkObjectDefinition.ts
|
|
959
|
+
function wireObjectTypeV2ToSdkObjectDefinition(objectTypeWithLink, v2) {
|
|
960
|
+
if (objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey] === void 0) {
|
|
961
|
+
throw new Error(`Primary key ${objectTypeWithLink.objectType.primaryKey} not found in ${objectTypeWithLink.objectType.apiName}`);
|
|
962
|
+
}
|
|
963
|
+
return {
|
|
964
|
+
apiName: objectTypeWithLink.objectType.apiName,
|
|
965
|
+
description: objectTypeWithLink.objectType.description,
|
|
966
|
+
primaryKeyType: wirePropertyV2ToSdkPrimaryKeyTypeDefinition(objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey]),
|
|
967
|
+
links: Object.fromEntries(objectTypeWithLink.linkTypes.map((linkType) => {
|
|
968
|
+
return [linkType.apiName, {
|
|
969
|
+
multiplicity: linkType.cardinality === "MANY",
|
|
970
|
+
targetType: linkType.objectTypeApiName
|
|
971
|
+
}];
|
|
972
|
+
})),
|
|
973
|
+
properties: Object.fromEntries(Object.entries(objectTypeWithLink.objectType.properties).map(([key, value]) => [key, wirePropertyV2ToSdkPropertyDefinition(value, !(v2 && objectTypeWithLink.objectType.primaryKey === key))]))
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
// src/shared/wireObjectTypeV2ToSdkObjectConst.ts
|
|
978
|
+
function wireObjectTypeV2ToSdkObjectConst(object, v2 = false) {
|
|
979
|
+
const uniqueLinkTargetTypes = new Set(object.linkTypes.map((a) => a.objectTypeApiName));
|
|
980
|
+
return `
|
|
981
|
+
export const ${object.objectType.apiName} = ${JSON.stringify(wireObjectTypeV2ToSdkObjectDefinition(object, v2), null, 2)} satisfies ObjectTypeDefinition<"${object.objectType.apiName}", ${uniqueLinkTargetTypes.size > 0 ? [...uniqueLinkTargetTypes].map((apiName) => `"${apiName}"`).join("|") : "never"}>;`;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// src/util/reservedKeywords.ts
|
|
985
|
+
var reservedKeywords = /* @__PURE__ */ new Set(["break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do", "else", "enum", "export", "extends", "false", "finally", "for", "function", "if", "import", "in", "instanceof", "new", "null", "return", "super", "switch", "this", "throw", "true", "try", "typeof", "var", "void", "while", "with", "implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"]);
|
|
986
|
+
function isReservedKeyword(name) {
|
|
987
|
+
return reservedKeywords.has(name);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// src/v1.1/wireObjectTypeV2ToV1ObjectInterfaceString.ts
|
|
991
|
+
function wireObjectTypeV2ToObjectInterfaceStringV1(objectTypeWithLinks) {
|
|
992
|
+
const uniqueLinkTargets = new Set(objectTypeWithLinks.linkTypes.map((a) => a.objectTypeApiName).filter((a) => a !== objectTypeWithLinks.objectType.apiName));
|
|
993
|
+
return `import type { OntologyObject, LocalDate, Timestamp, GeoShape, GeoPoint, Attachment, TimeSeries, MultiLink, SingleLink } from "@osdk/legacy-client";
|
|
994
|
+
${Array.from(uniqueLinkTargets).map((linkTarget) => `import type { ${linkTarget} } from "./${linkTarget}";`).join("\n")}
|
|
995
|
+
|
|
996
|
+
${getDescriptionIfPresent(objectTypeWithLinks.objectType.description)}export interface ${objectTypeWithLinks.objectType.apiName} extends OntologyObject {
|
|
997
|
+
readonly __apiName: "${objectTypeWithLinks.objectType.apiName}";
|
|
998
|
+
readonly __primaryKey: ${wirePropertyTypeV2ToTypeScriptType(objectTypeWithLinks.objectType.properties[objectTypeWithLinks.objectType.primaryKey].dataType)};
|
|
999
|
+
${Object.entries(objectTypeWithLinks.objectType.properties).flatMap(([propertyName, propertyDefinition]) => {
|
|
1000
|
+
const propertyType = wirePropertyTypeV2ToTypeScriptType(propertyDefinition.dataType);
|
|
1001
|
+
const entries = [`${getDescriptionIfPresent(propertyDefinition.description)}readonly ${propertyName}: ${propertyType} | undefined`];
|
|
1002
|
+
if (isReservedKeyword(propertyName)) {
|
|
1003
|
+
entries.push(`/** @deprecated please migrate to '${propertyName}' instead */
|
|
1004
|
+
readonly ${propertyName}_: ${propertyType} | undefined`);
|
|
1005
|
+
}
|
|
1006
|
+
return entries;
|
|
1007
|
+
}).join(";\n")}
|
|
1008
|
+
${objectTypeWithLinks.linkTypes.flatMap((linkType) => {
|
|
1009
|
+
const entries = [`readonly ${linkType.apiName}: ${linkType.cardinality === "MANY" ? "MultiLink" : "SingleLink"}<${linkType.objectTypeApiName}>`];
|
|
1010
|
+
return entries;
|
|
1011
|
+
}).join(";\n")}
|
|
1012
|
+
}
|
|
1013
|
+
`;
|
|
1014
|
+
}
|
|
1015
|
+
function wirePropertyTypeV2ToTypeScriptType(property) {
|
|
1016
|
+
switch (property.type) {
|
|
1017
|
+
case "string":
|
|
1018
|
+
return "string";
|
|
1019
|
+
case "boolean":
|
|
1020
|
+
return "boolean";
|
|
1021
|
+
case "array":
|
|
1022
|
+
return wirePropertyTypeV2ToTypeScriptType(property.subType) + "[]";
|
|
1023
|
+
case "integer":
|
|
1024
|
+
return "number";
|
|
1025
|
+
case "attachment":
|
|
1026
|
+
return "Attachment";
|
|
1027
|
+
case "byte":
|
|
1028
|
+
return "number";
|
|
1029
|
+
case "date":
|
|
1030
|
+
return "LocalDate";
|
|
1031
|
+
case "decimal":
|
|
1032
|
+
return "number";
|
|
1033
|
+
case "double":
|
|
1034
|
+
return "number";
|
|
1035
|
+
case "float":
|
|
1036
|
+
return "number";
|
|
1037
|
+
case "geopoint":
|
|
1038
|
+
return "GeoPoint";
|
|
1039
|
+
case "geoshape":
|
|
1040
|
+
return "GeoShape";
|
|
1041
|
+
case "long":
|
|
1042
|
+
return "number";
|
|
1043
|
+
case "short":
|
|
1044
|
+
return "number";
|
|
1045
|
+
case "timestamp":
|
|
1046
|
+
return "Timestamp";
|
|
1047
|
+
case "timeseries":
|
|
1048
|
+
return property.itemType.type === "string" ? `TimeSeries<string>` : `TimeSeries<number>`;
|
|
1049
|
+
default:
|
|
1050
|
+
throw new Error(`Unknown property type ${property}`);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
function getDescriptionIfPresent(description) {
|
|
1054
|
+
if (description) {
|
|
1055
|
+
return `/**
|
|
1056
|
+
* ${description}
|
|
261
1057
|
*/
|
|
262
|
-
|
|
1058
|
+
`;
|
|
1059
|
+
}
|
|
1060
|
+
return "";
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// src/v1.1/generatePerObjectInterfaceAndDataFiles.ts
|
|
1064
|
+
async function generatePerObjectInterfaceAndDataFiles(ontology, fs, outDir, importExt = "") {
|
|
1065
|
+
await fs.mkdir(outDir, {
|
|
1066
|
+
recursive: true
|
|
1067
|
+
});
|
|
1068
|
+
await Promise.all(Object.values(ontology.objectTypes).map(async (object) => {
|
|
1069
|
+
object.linkTypes;
|
|
1070
|
+
await fs.writeFile(path15__default.join(outDir, `${object.objectType.apiName}.ts`), await formatTs(`
|
|
263
1071
|
import { ObjectTypeDefinition } from "@osdk/api";
|
|
264
|
-
${
|
|
1072
|
+
${wireObjectTypeV2ToObjectInterfaceStringV1(object)}
|
|
265
1073
|
|
|
266
|
-
${
|
|
267
|
-
`));
|
|
268
|
-
|
|
269
|
-
`
|
|
1074
|
+
${wireObjectTypeV2ToSdkObjectConst(object)}
|
|
1075
|
+
`));
|
|
1076
|
+
}));
|
|
1077
|
+
await fs.writeFile(path15__default.join(outDir, "index.ts"), await formatTs(`
|
|
1078
|
+
${Object.keys(ontology.objectTypes).map((apiName) => `export * from "./${apiName}${importExt}";`).join("\n")}
|
|
270
1079
|
export type { ObjectSet } from "@osdk/legacy-client";
|
|
271
1080
|
|
|
272
|
-
`));
|
|
1081
|
+
`));
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
// src/shared/isNullableQueryDataType.ts
|
|
1085
|
+
function isNullableQueryDataType(input) {
|
|
1086
|
+
if (input.type === "null") {
|
|
1087
|
+
return true;
|
|
1088
|
+
}
|
|
1089
|
+
if (input.type === "union") {
|
|
1090
|
+
return input.unionTypes.some((t) => isNullableQueryDataType(t));
|
|
1091
|
+
}
|
|
1092
|
+
return false;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
// src/shared/wireQueryDataTypeToQueryDataTypeDefinition.ts
|
|
1096
|
+
function wireQueryDataTypeToQueryDataTypeDefinition(input) {
|
|
1097
|
+
switch (input.type) {
|
|
1098
|
+
case "double":
|
|
1099
|
+
case "float":
|
|
1100
|
+
case "integer":
|
|
1101
|
+
case "long":
|
|
1102
|
+
case "attachment":
|
|
1103
|
+
case "boolean":
|
|
1104
|
+
case "date":
|
|
1105
|
+
case "string":
|
|
1106
|
+
case "timestamp":
|
|
1107
|
+
return {
|
|
1108
|
+
type: input.type,
|
|
1109
|
+
nullable: false
|
|
1110
|
+
};
|
|
1111
|
+
case "object":
|
|
1112
|
+
return {
|
|
1113
|
+
type: "object",
|
|
1114
|
+
object: input.objectTypeApiName,
|
|
1115
|
+
nullable: false
|
|
1116
|
+
};
|
|
1117
|
+
case "objectSet":
|
|
1118
|
+
return {
|
|
1119
|
+
type: "objectSet",
|
|
1120
|
+
objectSet: input.objectTypeApiName,
|
|
1121
|
+
nullable: false
|
|
1122
|
+
};
|
|
1123
|
+
case "array":
|
|
1124
|
+
return {
|
|
1125
|
+
...wireQueryDataTypeToQueryDataTypeDefinition(input.subType),
|
|
1126
|
+
multiplicity: true
|
|
1127
|
+
};
|
|
1128
|
+
case "set":
|
|
1129
|
+
return {
|
|
1130
|
+
type: "set",
|
|
1131
|
+
set: wireQueryDataTypeToQueryDataTypeDefinition(input.subType),
|
|
1132
|
+
nullable: false
|
|
1133
|
+
};
|
|
1134
|
+
case "union":
|
|
1135
|
+
const allowNulls = isNullableQueryDataType(input);
|
|
1136
|
+
if (allowNulls && input.unionTypes.length === 2) {
|
|
1137
|
+
const nonnull = input.unionTypes.find((t) => t.type !== null);
|
|
1138
|
+
if (nonnull) {
|
|
1139
|
+
return {
|
|
1140
|
+
...wireQueryDataTypeToQueryDataTypeDefinition(nonnull),
|
|
1141
|
+
nullable: true
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
return {
|
|
1146
|
+
type: "union",
|
|
1147
|
+
union: input.unionTypes.reduce((acc, t) => {
|
|
1148
|
+
if (t.type === "null") {
|
|
1149
|
+
return acc;
|
|
1150
|
+
}
|
|
1151
|
+
acc.push(wireQueryDataTypeToQueryDataTypeDefinition(t));
|
|
1152
|
+
return acc;
|
|
1153
|
+
}, []),
|
|
1154
|
+
nullable: allowNulls
|
|
1155
|
+
};
|
|
1156
|
+
case "struct":
|
|
1157
|
+
return {
|
|
1158
|
+
type: "struct",
|
|
1159
|
+
struct: Object.fromEntries(input.fields.map((f) => [f.name, wireQueryDataTypeToQueryDataTypeDefinition(f.fieldType)])),
|
|
1160
|
+
nullable: false
|
|
1161
|
+
};
|
|
1162
|
+
case "twoDimensionalAggregation":
|
|
1163
|
+
return {
|
|
1164
|
+
type: "twoDimensionalAggregation",
|
|
1165
|
+
twoDimensionalAggregation: get2DQueryAggregationProps(input)
|
|
1166
|
+
};
|
|
1167
|
+
case "threeDimensionalAggregation":
|
|
1168
|
+
return {
|
|
1169
|
+
type: "threeDimensionalAggregation",
|
|
1170
|
+
threeDimensionalAggregation: get3DQueryAggregationProps(input)
|
|
1171
|
+
};
|
|
1172
|
+
case "null":
|
|
1173
|
+
case "unsupported":
|
|
1174
|
+
throw new Error(`Accidentally tried to handle QueryDataType.type ${input.type}`);
|
|
1175
|
+
default:
|
|
1176
|
+
throw new Error(`Unsupported QueryDataType.type ${input.type}`);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
function get2DQueryAggregationProps(input) {
|
|
1180
|
+
if (input.keyType.type === "range") {
|
|
1181
|
+
return {
|
|
1182
|
+
keyType: input.keyType.type,
|
|
1183
|
+
keySubtype: input.keyType.subType.type,
|
|
1184
|
+
valueType: input.valueType.type
|
|
1185
|
+
};
|
|
1186
|
+
} else {
|
|
1187
|
+
if (guardInvalidKeyTypes(input.keyType)) {
|
|
1188
|
+
return {
|
|
1189
|
+
keyType: input.keyType.type,
|
|
1190
|
+
valueType: input.valueType.type
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
throw new Error(`Cannot create 2D aggregation with ${input.keyType.type} as its type`);
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
function get3DQueryAggregationProps(input) {
|
|
1197
|
+
if (input.keyType.type === "range") {
|
|
1198
|
+
return {
|
|
1199
|
+
keyType: input.keyType.type,
|
|
1200
|
+
keySubtype: input.keyType.subType.type,
|
|
1201
|
+
valueType: get2DQueryAggregationProps(input.valueType)
|
|
1202
|
+
};
|
|
1203
|
+
} else {
|
|
1204
|
+
if (guardInvalidKeyTypes(input.keyType)) {
|
|
1205
|
+
return {
|
|
1206
|
+
keyType: input.keyType.type,
|
|
1207
|
+
valueType: get2DQueryAggregationProps(input.valueType)
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
throw new Error(`Cannot create 3D aggregation with ${input.keyType.type} as its type`);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
function guardInvalidKeyTypes(key) {
|
|
1214
|
+
return key.type === "string" || key.type === "boolean";
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
// src/shared/wireQueryTypeV2ToSdkQueryDefinition.ts
|
|
1218
|
+
function wireQueryTypeV2ToSdkQueryDefinition(input) {
|
|
1219
|
+
return {
|
|
1220
|
+
apiName: input.apiName,
|
|
1221
|
+
description: input.description,
|
|
1222
|
+
displayName: input.displayName,
|
|
1223
|
+
version: input.version,
|
|
1224
|
+
parameters: Object.fromEntries(Object.entries(input.parameters).map(([name, parameter]) => [name, wireQueryParameterV2ToQueryParameterDefinition(parameter)])),
|
|
1225
|
+
output: wireQueryDataTypeToQueryDataTypeDefinition(input.output)
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
function wireQueryParameterV2ToQueryParameterDefinition(parameter) {
|
|
1229
|
+
return {
|
|
1230
|
+
description: parameter.description,
|
|
1231
|
+
...wireQueryDataTypeToQueryDataTypeDefinition(parameter.dataType)
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// src/v1.1/generatePerQueryDataFiles.ts
|
|
1236
|
+
async function generatePerQueryDataFiles(ontology, fs, outDir, importExt = "") {
|
|
1237
|
+
await fs.mkdir(outDir, {
|
|
1238
|
+
recursive: true
|
|
1239
|
+
});
|
|
1240
|
+
await Promise.all(Object.values(ontology.queryTypes).map(async (query) => {
|
|
1241
|
+
const objectTypes = getObjectTypesFromQuery(query);
|
|
1242
|
+
await fs.writeFile(path15__default.join(outDir, `${query.apiName}.ts`), await formatTs(`
|
|
273
1243
|
import { QueryDefinition } from "@osdk/api";
|
|
274
1244
|
|
|
275
|
-
export const ${
|
|
276
|
-
|
|
277
|
-
`
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
1245
|
+
export const ${query.apiName} = ${JSON.stringify(wireQueryTypeV2ToSdkQueryDefinition(query))} satisfies QueryDefinition<"${query.apiName}", ${objectTypes.length > 0 ? objectTypes.map((apiName) => `"${apiName}"`).join("|") : "never"}>;`));
|
|
1246
|
+
}));
|
|
1247
|
+
await fs.writeFile(path15__default.join(outDir, "index.ts"), await formatTs(`
|
|
1248
|
+
${Object.values(ontology.queryTypes).map((query) => `export * from "./${query.apiName}${importExt}";`).join("\n")}
|
|
1249
|
+
`));
|
|
1250
|
+
}
|
|
1251
|
+
function getObjectTypesFromQuery(query) {
|
|
1252
|
+
const types = /* @__PURE__ */ new Set();
|
|
1253
|
+
for (const {
|
|
1254
|
+
dataType
|
|
1255
|
+
} of Object.values(query.parameters)) {
|
|
1256
|
+
getObjectTypesFromDataType(dataType, types);
|
|
1257
|
+
}
|
|
1258
|
+
getObjectTypesFromDataType(query.output, types);
|
|
1259
|
+
return Array.from(types);
|
|
1260
|
+
}
|
|
1261
|
+
function getObjectTypesFromDataType(dataType, types) {
|
|
1262
|
+
switch (dataType.type) {
|
|
1263
|
+
case "array":
|
|
1264
|
+
case "set":
|
|
1265
|
+
getObjectTypesFromDataType(dataType.subType, types);
|
|
1266
|
+
return;
|
|
1267
|
+
case "object":
|
|
1268
|
+
types.add(dataType.objectTypeApiName);
|
|
1269
|
+
return;
|
|
1270
|
+
case "objectSet":
|
|
1271
|
+
types.add(dataType.objectTypeApiName);
|
|
1272
|
+
return;
|
|
1273
|
+
case "struct":
|
|
1274
|
+
for (const prop of Object.values(dataType.fields)) {
|
|
1275
|
+
getObjectTypesFromDataType(prop.fieldType, types);
|
|
1276
|
+
}
|
|
1277
|
+
return;
|
|
1278
|
+
case "union":
|
|
1279
|
+
for (const type of dataType.unionTypes) {
|
|
1280
|
+
getObjectTypesFromDataType(type, types);
|
|
1281
|
+
}
|
|
1282
|
+
return;
|
|
1283
|
+
case "attachment":
|
|
1284
|
+
case "boolean":
|
|
1285
|
+
case "date":
|
|
1286
|
+
case "double":
|
|
1287
|
+
case "float":
|
|
1288
|
+
case "integer":
|
|
1289
|
+
case "long":
|
|
1290
|
+
case "null":
|
|
1291
|
+
case "string":
|
|
1292
|
+
case "threeDimensionalAggregation":
|
|
1293
|
+
case "timestamp":
|
|
1294
|
+
case "twoDimensionalAggregation":
|
|
1295
|
+
case "unsupported":
|
|
1296
|
+
return;
|
|
1297
|
+
default:
|
|
1298
|
+
throw new Error(`Cannot find object types from unsupported QueryDataType ${dataType.type}`);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
async function generateQueries(ontology, fs, outDir, importExt = "") {
|
|
1302
|
+
const importedObjects = /* @__PURE__ */ new Set();
|
|
1303
|
+
const signatures = [];
|
|
1304
|
+
for (const query of Object.values(ontology.queryTypes)) {
|
|
1305
|
+
const jsDocBlock = ["/**"];
|
|
1306
|
+
if (query.description) {
|
|
1307
|
+
jsDocBlock.push(`* ${query.description}`);
|
|
1308
|
+
}
|
|
1309
|
+
const outputType = handleQueryDataType(query.output, importedObjects, true);
|
|
1310
|
+
const paramEntries = [];
|
|
1311
|
+
for (const [name, parameter] of Object.entries(query.parameters)) {
|
|
1312
|
+
const nullable = isNullableQueryDataType(parameter.dataType);
|
|
1313
|
+
const type = handleQueryDataType(parameter.dataType, importedObjects, false);
|
|
1314
|
+
paramEntries.push(`"${name}"${nullable ? "?" : ""}: ${type}`);
|
|
1315
|
+
jsDocBlock.push(`* @param {${sanitizeDocTypeName(type)}} params.${name}${parameter.description ? ` - ${parameter.description}` : ""}`);
|
|
1316
|
+
}
|
|
1317
|
+
const param = paramEntries.length === 0 ? "" : `params: { ${paramEntries.join("; ")} }`;
|
|
1318
|
+
jsDocBlock.push(`* @returns ${sanitizeDocTypeName(outputType)}`, "*/");
|
|
1319
|
+
signatures.push(`
|
|
1320
|
+
${jsDocBlock.join("\n")}
|
|
1321
|
+
${query.apiName}(${param}): Promise<Result<QueryResponse<${outputType}>, QueryError>>;
|
|
1322
|
+
`);
|
|
1323
|
+
}
|
|
1324
|
+
await fs.mkdir(outDir, {
|
|
1325
|
+
recursive: true
|
|
1326
|
+
});
|
|
1327
|
+
await fs.writeFile(path15__default.join(outDir, "Queries.ts"), await formatTs(`
|
|
283
1328
|
import type { QueryResponse, QueryError, Result, Timestamp, LocalDate, Range, Attachment, ObjectSet, TwoDimensionalAggregation, ThreeDimensionalAggregation } from "@osdk/legacy-client";
|
|
284
|
-
${Array.from(
|
|
285
|
-
`)}
|
|
1329
|
+
${Array.from(importedObjects).map((importedObject) => `import type { ${importedObject} } from "../objects/${importedObject}${importExt}";`).join("\n")}
|
|
286
1330
|
|
|
287
1331
|
export interface Queries {
|
|
288
|
-
${
|
|
289
|
-
|
|
1332
|
+
${signatures.join("\n")}
|
|
1333
|
+
}
|
|
1334
|
+
`));
|
|
1335
|
+
}
|
|
1336
|
+
function handleQueryDataType(dataType, importedObjects, isReturnValue) {
|
|
1337
|
+
switch (dataType.type) {
|
|
1338
|
+
case "boolean":
|
|
1339
|
+
return "boolean";
|
|
1340
|
+
case "string":
|
|
1341
|
+
return "string";
|
|
1342
|
+
case "double":
|
|
1343
|
+
case "float":
|
|
1344
|
+
case "integer":
|
|
1345
|
+
case "long":
|
|
1346
|
+
return "number";
|
|
1347
|
+
case "date":
|
|
1348
|
+
return "LocalDate";
|
|
1349
|
+
case "timestamp":
|
|
1350
|
+
return "Timestamp";
|
|
1351
|
+
case "attachment":
|
|
1352
|
+
return "Attachment";
|
|
1353
|
+
case "array":
|
|
1354
|
+
return `Array<${handleQueryDataType(dataType.subType, importedObjects, isReturnValue)}>`;
|
|
1355
|
+
case "object": {
|
|
1356
|
+
const objectType = dataType.objectTypeApiName;
|
|
1357
|
+
importedObjects.add(objectType);
|
|
1358
|
+
return isReturnValue ? objectType : `${objectType} | ${objectType}["__primaryKey"]`;
|
|
290
1359
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
1360
|
+
case "objectSet": {
|
|
1361
|
+
const objectType = dataType.objectTypeApiName;
|
|
1362
|
+
importedObjects.add(objectType);
|
|
1363
|
+
return `ObjectSet<${objectType}>`;
|
|
1364
|
+
}
|
|
1365
|
+
case "set":
|
|
1366
|
+
return `Set<${handleQueryDataType(dataType.subType, importedObjects, isReturnValue)}>`;
|
|
1367
|
+
case "struct":
|
|
1368
|
+
const properties = dataType.fields.map((field) => {
|
|
1369
|
+
const isNullable = isNullableQueryDataType(field.fieldType);
|
|
1370
|
+
return `${field.name}${isNullable ? "?" : ""}: ${handleQueryDataType(field.fieldType, importedObjects, isReturnValue)}`;
|
|
1371
|
+
});
|
|
1372
|
+
return `{ ${properties.join(",\n")} }`;
|
|
1373
|
+
case "union":
|
|
1374
|
+
return dataType.unionTypes.map((type) => handleQueryDataType(type, importedObjects, isReturnValue)).filter((type) => type !== "null").join("|");
|
|
1375
|
+
case "twoDimensionalAggregation":
|
|
1376
|
+
dataType.valueType;
|
|
1377
|
+
return `TwoDimensionalAggregation<
|
|
1378
|
+
${aggregationKeyToTypescriptType(dataType.keyType)},
|
|
1379
|
+
${aggregationValueToTypescriptType(dataType.valueType)}
|
|
1380
|
+
>`;
|
|
1381
|
+
case "threeDimensionalAggregation":
|
|
1382
|
+
return `ThreeDimensionalAggregation<
|
|
1383
|
+
${aggregationKeyToTypescriptType(dataType.keyType)},
|
|
1384
|
+
${aggregationKeyToTypescriptType(dataType.valueType.keyType)},
|
|
1385
|
+
${aggregationValueToTypescriptType(dataType.valueType.valueType)}
|
|
1386
|
+
>`;
|
|
1387
|
+
case "null":
|
|
1388
|
+
return "null";
|
|
1389
|
+
case "unsupported":
|
|
1390
|
+
throw new Error("Cannot generate queries for unsupported type");
|
|
1391
|
+
default:
|
|
1392
|
+
throw new Error(`Cannot generate queries for type ${dataType.type}`);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
function aggregationKeyToTypescriptType(keyType) {
|
|
1396
|
+
switch (keyType.type) {
|
|
1397
|
+
case "boolean":
|
|
1398
|
+
return "boolean";
|
|
1399
|
+
case "double":
|
|
1400
|
+
case "integer":
|
|
1401
|
+
return "number";
|
|
1402
|
+
case "string":
|
|
1403
|
+
return "string";
|
|
1404
|
+
case "date":
|
|
1405
|
+
return "LocalDate";
|
|
1406
|
+
case "timestamp":
|
|
1407
|
+
return "Timestamp";
|
|
1408
|
+
case "range":
|
|
1409
|
+
return `Range<${aggregationRangeToTypescriptType(keyType.subType)}>`;
|
|
1410
|
+
default:
|
|
1411
|
+
throw new Error(`Unknown TwoDimensionalAggregation keyType ${keyType.type}`);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
function aggregationRangeToTypescriptType(subType) {
|
|
1415
|
+
switch (subType.type) {
|
|
1416
|
+
case "date":
|
|
1417
|
+
return "LocalDate";
|
|
1418
|
+
case "double":
|
|
1419
|
+
case "integer":
|
|
1420
|
+
return "number";
|
|
1421
|
+
case "timestamp":
|
|
1422
|
+
return "Timestamp";
|
|
1423
|
+
default:
|
|
1424
|
+
throw new Error(`Unsupported QueryAggregationRangeSubType ${subType.type}`);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
function aggregationValueToTypescriptType(valueType) {
|
|
1428
|
+
switch (valueType.type) {
|
|
1429
|
+
case "date":
|
|
1430
|
+
return "LocalDate";
|
|
1431
|
+
case "double":
|
|
1432
|
+
return "number";
|
|
1433
|
+
case "timestamp":
|
|
1434
|
+
return "Timestamp";
|
|
1435
|
+
default:
|
|
1436
|
+
throw new Error(`Unsupported QueryAggregationValueType ${valueType.type}`);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
function sanitizeDocTypeName(type) {
|
|
1440
|
+
return type.replace(/\s/g, "");
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
// src/v1.1/generateClientSdkVersionOneDotOne.ts
|
|
1444
|
+
async function generateClientSdkVersionOneDotOne(ontology, fs, outDir, packageType = "commonjs") {
|
|
1445
|
+
const importExt = packageType === "module" ? ".js" : "";
|
|
1446
|
+
const objectsDir = path15.join(outDir, "ontology", "objects");
|
|
1447
|
+
const actionsDir = path15.join(outDir, "ontology", "actions");
|
|
1448
|
+
const queriesDir = path15.join(outDir, "ontology", "queries");
|
|
1449
|
+
await verifyOutdir(outDir, fs);
|
|
1450
|
+
const sanitizedOntology = sanitizeMetadata(ontology);
|
|
1451
|
+
await generateFoundryClientFile(fs, outDir, importExt);
|
|
1452
|
+
await generateMetadataFile(sanitizedOntology, fs, outDir, importExt);
|
|
1453
|
+
await generateOntologyIndexFile(fs, path15.join(outDir, "ontology"));
|
|
1454
|
+
await generateObjectsInterfaceFile(sanitizedOntology, fs, objectsDir, importExt);
|
|
1455
|
+
await generateObjectsInterfaceSupportFiles(sanitizedOntology, fs, path15.join(objectsDir, "objects-api"), importExt);
|
|
1456
|
+
await generatePerObjectInterfaceAndDataFiles(sanitizedOntology, fs, objectsDir, importExt);
|
|
1457
|
+
await generateActions(sanitizedOntology, fs, actionsDir, importExt);
|
|
1458
|
+
await generatePerActionDataFiles(sanitizedOntology, fs, actionsDir, importExt);
|
|
1459
|
+
await generateQueries(sanitizedOntology, fs, queriesDir, importExt);
|
|
1460
|
+
await generatePerQueryDataFiles(sanitizedOntology, fs, queriesDir, importExt);
|
|
1461
|
+
await generateIndexFile(fs, outDir, importExt);
|
|
1462
|
+
await generateBackCompatDeprecatedExports(fs, outDir);
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
// src/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.ts
|
|
1466
|
+
function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceType, v2 = false) {
|
|
1467
|
+
return `
|
|
1468
|
+
export const ${interfaceType.apiName} = ${JSON.stringify(wireInterfaceTypeV2ToSdkObjectDefinition(interfaceType), null, 2)} satisfies InterfaceDefinition<"${interfaceType.apiName}", "">;`;
|
|
1469
|
+
}
|
|
1470
|
+
function wireInterfaceTypeV2ToSdkObjectDefinition(interfaceType, v2) {
|
|
1471
|
+
return {
|
|
1472
|
+
apiName: interfaceType.apiName,
|
|
1473
|
+
description: interfaceType.description,
|
|
1474
|
+
properties: Object.fromEntries(Object.entries(interfaceType.properties).map(([key, value]) => {
|
|
1475
|
+
return [key, wirePropertyV2ToSdkPropertyDefinition(value, true)];
|
|
1476
|
+
}))
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
async function generateOntologyMetadataFile(ontology, fs, outDir) {
|
|
1480
|
+
fs.writeFile(path15__default.join(outDir, "OntologyMetadata.ts"), await formatTs(`
|
|
301
1481
|
export const OntologyMetadata = {
|
|
302
|
-
ontologyRid: "${
|
|
303
|
-
ontologyApiName: "${
|
|
1482
|
+
ontologyRid: "${ontology.ontology.rid}",
|
|
1483
|
+
ontologyApiName: "${ontology.ontology.apiName}",
|
|
304
1484
|
userAgent: "foundry-typescript-osdk/2.0.0",
|
|
305
1485
|
}
|
|
306
|
-
`));
|
|
307
|
-
|
|
308
|
-
|
|
1486
|
+
`));
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
// src/v2.0/generateClientSdkVersionTwoPointZero.ts
|
|
1490
|
+
async function generateClientSdkVersionTwoPointZero(ontology, fs, outDir, packageType = "commonjs") {
|
|
1491
|
+
await verifyOutdir(outDir, fs);
|
|
1492
|
+
const sanitizedOntology = sanitizeMetadata(ontology);
|
|
1493
|
+
const objectNames = Object.keys(sanitizedOntology.objectTypes);
|
|
1494
|
+
const actionNames = Object.keys(sanitizedOntology.actionTypes);
|
|
1495
|
+
const interfaceNames = Object.keys(sanitizedOntology.__UNSTABLE_interfaceTypes ?? {});
|
|
1496
|
+
const importExt = packageType === "module" ? ".js" : "";
|
|
1497
|
+
await fs.mkdir(outDir, {
|
|
1498
|
+
recursive: true
|
|
1499
|
+
});
|
|
1500
|
+
fs.writeFile(path15__default.join(outDir, "index.ts"), await formatTs(`
|
|
1501
|
+
export { Ontology } from "./Ontology${importExt}";
|
|
1502
|
+
`));
|
|
1503
|
+
await generateOntologyMetadataFile(sanitizedOntology, fs, outDir);
|
|
1504
|
+
await fs.writeFile(path15__default.join(outDir, "Ontology.ts"), await formatTs(`
|
|
309
1505
|
import type { OntologyDefinition } from "@osdk/api";
|
|
310
|
-
import * as Actions from "./ontology/actions/index${
|
|
311
|
-
import * as Objects from "./ontology/objects${
|
|
312
|
-
import * as Interfaces from "./ontology/interfaces${
|
|
313
|
-
import { OntologyMetadata } from "./OntologyMetadata${
|
|
1506
|
+
import * as Actions from "./ontology/actions/index${importExt}";
|
|
1507
|
+
import * as Objects from "./ontology/objects${importExt}";
|
|
1508
|
+
import * as Interfaces from "./ontology/interfaces${importExt}";
|
|
1509
|
+
import { OntologyMetadata } from "./OntologyMetadata${importExt}";
|
|
314
1510
|
|
|
315
1511
|
const _Ontology = {
|
|
316
1512
|
metadata: OntologyMetadata,
|
|
317
1513
|
objects: {
|
|
318
|
-
${
|
|
319
|
-
|
|
1514
|
+
${objectNames.map((objectName) => {
|
|
1515
|
+
return `${objectName}: Objects.${objectName}`;
|
|
1516
|
+
}).join(",\n")}
|
|
320
1517
|
|
|
321
1518
|
},
|
|
322
1519
|
actions: {
|
|
323
|
-
${
|
|
324
|
-
|
|
1520
|
+
${actionNames.map((actionName) => {
|
|
1521
|
+
return `${actionName}: Actions.${actionName}`;
|
|
1522
|
+
}).join(",\n")}
|
|
325
1523
|
},
|
|
326
1524
|
queries: {
|
|
327
1525
|
// TODO
|
|
328
1526
|
},
|
|
329
1527
|
interfaces: {
|
|
330
|
-
${
|
|
331
|
-
|
|
1528
|
+
${interfaceNames.map((objectName) => {
|
|
1529
|
+
return `${objectName}: Interfaces.${objectName}`;
|
|
1530
|
+
}).join(",\n")}
|
|
332
1531
|
|
|
333
1532
|
}
|
|
334
|
-
} satisfies OntologyDefinition<${
|
|
1533
|
+
} satisfies OntologyDefinition<${objectNames.map((n) => `"${n}"`).join("|")}>;
|
|
335
1534
|
|
|
336
1535
|
type _Ontology = typeof _Ontology;
|
|
337
1536
|
export interface Ontology extends _Ontology {}
|
|
338
1537
|
export const Ontology = _Ontology as Ontology;
|
|
339
|
-
`))
|
|
1538
|
+
`));
|
|
1539
|
+
await fs.mkdir(path15__default.join(outDir, "ontology", "objects"), {
|
|
1540
|
+
recursive: true
|
|
1541
|
+
});
|
|
1542
|
+
for (const name of objectNames) {
|
|
1543
|
+
const obj = ontology.objectTypes[name];
|
|
1544
|
+
await fs.writeFile(path15__default.join(outDir, "ontology", `objects`, `${name}.ts`), await formatTs(`
|
|
340
1545
|
|
|
341
1546
|
import type { ObjectTypeDefinition } from "@osdk/api";
|
|
342
1547
|
|
|
343
|
-
${
|
|
1548
|
+
${wireObjectTypeV2ToSdkObjectConst(obj, true)}
|
|
344
1549
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
1550
|
+
${/* TODO: FIXME
|
|
1551
|
+
// wireObjectTypeV2ToObjectDefinitionInterfaceString(
|
|
1552
|
+
// obj,
|
|
1553
|
+
// )
|
|
1554
|
+
*/
|
|
1555
|
+
""}
|
|
1556
|
+
`));
|
|
1557
|
+
}
|
|
1558
|
+
await generateOntologyInterfaces(fs, outDir, interfaceNames, ontology, importExt);
|
|
1559
|
+
const actionsDir = path15__default.join(outDir, "ontology", "actions");
|
|
1560
|
+
await fs.mkdir(actionsDir, {
|
|
1561
|
+
recursive: true
|
|
1562
|
+
});
|
|
1563
|
+
await generatePerActionDataFiles(sanitizedOntology, fs, actionsDir, importExt);
|
|
1564
|
+
await fs.writeFile(path15__default.join(outDir, "ontology", "objects.ts"), await formatTs(`
|
|
1565
|
+
${Object.keys(ontology.objectTypes).map((apiName) => `export * from "./objects/${apiName}${importExt}";`).join("\n")}
|
|
1566
|
+
`));
|
|
1567
|
+
}
|
|
1568
|
+
async function generateOntologyInterfaces(fs, outDir, interfaceNames, ontology, importExt) {
|
|
1569
|
+
const interfacesDir = path15__default.join(outDir, "ontology", "interfaces");
|
|
1570
|
+
await fs.mkdir(interfacesDir, {
|
|
1571
|
+
recursive: true
|
|
1572
|
+
});
|
|
1573
|
+
for (const name of interfaceNames) {
|
|
1574
|
+
const obj = ontology.__UNSTABLE_interfaceTypes[name];
|
|
1575
|
+
await fs.writeFile(path15__default.join(interfacesDir, `${name}.ts`), await formatTs(`
|
|
350
1576
|
|
|
351
1577
|
import type { InterfaceDefinition } from "@osdk/api";
|
|
352
1578
|
|
|
353
|
-
${
|
|
354
|
-
`));
|
|
355
|
-
|
|
356
|
-
`
|
|
357
|
-
`))
|
|
1579
|
+
${__UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(obj, true)}
|
|
1580
|
+
`));
|
|
1581
|
+
}
|
|
1582
|
+
await fs.writeFile(interfacesDir + ".ts", await formatTs(`
|
|
1583
|
+
${Object.keys(ontology.__UNSTABLE_interfaceTypes ?? {}).map((apiName) => `export * from "./interfaces/${apiName}${importExt}";`).join("\n")}
|
|
1584
|
+
`));
|
|
1585
|
+
}
|
|
358
1586
|
|
|
359
|
-
export {
|
|
1587
|
+
export { generateClientSdkVersionOneDotOne, generateClientSdkVersionTwoPointZero };
|
|
360
1588
|
//# sourceMappingURL=out.js.map
|
|
361
1589
|
//# sourceMappingURL=index.mjs.map
|