@osdk/generator 1.10.0 → 1.11.0-main-20240514141215
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 +15 -0
- package/build/js/index.browser.mjs +1888 -0
- package/build/js/index.browser.mjs.map +1 -0
- package/build/js/index.cjs +1 -1
- package/build/js/index.cjs.map +1 -1
- package/build/js/index.mjs +1 -1
- package/build/js/index.mjs.map +1 -1
- package/build/types/util/test/TodoWireOntology.d.ts +2 -0
- package/build/types/util/test/TodoWireOntology.d.ts.map +1 -1
- package/package.json +9 -7
|
@@ -0,0 +1,1888 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path16 from 'path';
|
|
3
|
+
import path16__default, { join } from 'path';
|
|
4
|
+
import { format } from 'prettier';
|
|
5
|
+
import organizeImports from 'prettier-plugin-organize-imports';
|
|
6
|
+
import { wireObjectTypeFullMetadataToSdkObjectTypeDefinition, __UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition } from '@osdk/generator-converters';
|
|
7
|
+
|
|
8
|
+
// src/generateClientSdkPackage.ts
|
|
9
|
+
|
|
10
|
+
// src/util/deleteUndefineds.ts
|
|
11
|
+
function deleteUndefineds(obj) {
|
|
12
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== void 0));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/util/stringify.ts
|
|
16
|
+
var defaultCustomizer = (value, defaultValueFormatter, key, defaultKeyFormatter) => {
|
|
17
|
+
return [defaultKeyFormatter(key), defaultValueFormatter(value)];
|
|
18
|
+
};
|
|
19
|
+
function stringify(obj, customizer = {}, separator = ",\n") {
|
|
20
|
+
const defaultKeyFormatter = (key) => `${JSON.stringify(key)}`;
|
|
21
|
+
const entries = [];
|
|
22
|
+
const sortedKeys = Object.keys(obj).sort((a, b) => a.localeCompare(b));
|
|
23
|
+
for (const key of sortedKeys) {
|
|
24
|
+
const value = obj[key];
|
|
25
|
+
const res = (customizer[key] ?? customizer["*"] ?? defaultCustomizer)(value, (value2) => JSON.stringify(value2, null, 2), key, defaultKeyFormatter);
|
|
26
|
+
if (res) {
|
|
27
|
+
if (typeof res === "string") {
|
|
28
|
+
entries.push(`${defaultKeyFormatter(key)}: ${res}`);
|
|
29
|
+
} else {
|
|
30
|
+
entries.push(`${res[0]}: ${res[1]}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return entries.join(separator);
|
|
35
|
+
}
|
|
36
|
+
function formatTs(contents) {
|
|
37
|
+
return format(contents, {
|
|
38
|
+
parser: "typescript",
|
|
39
|
+
singleQuote: true,
|
|
40
|
+
trailingComma: "all",
|
|
41
|
+
plugins: [organizeImports],
|
|
42
|
+
tabWidth: 2,
|
|
43
|
+
printWidth: 120
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/util/reservedKeywords.ts
|
|
48
|
+
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"]);
|
|
49
|
+
function isReservedKeyword(name) {
|
|
50
|
+
return reservedKeywords.has(name);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/v1.1/wireObjectTypeV2ToV1ObjectInterfaceString.ts
|
|
54
|
+
function wireObjectTypeV2ToObjectInterfaceStringV1(objectTypeWithLinks, importExt = "") {
|
|
55
|
+
const uniqueLinkTargets = new Set(objectTypeWithLinks.linkTypes.map((a) => a.objectTypeApiName).filter((a) => a !== objectTypeWithLinks.objectType.apiName));
|
|
56
|
+
return `import type { OntologyObject, LocalDate, Timestamp, GeoShape, GeoPoint, Attachment, TimeSeries, MultiLink, SingleLink } from "@osdk/legacy-client";
|
|
57
|
+
${Array.from(uniqueLinkTargets).map((linkTarget) => `import type { ${linkTarget} } from "./${linkTarget}${importExt}";`).join("\n")}
|
|
58
|
+
|
|
59
|
+
${getDescriptionIfPresent(objectTypeWithLinks.objectType.description)}
|
|
60
|
+
export interface ${objectTypeWithLinks.objectType.apiName} extends OntologyObject {
|
|
61
|
+
/** @deprecated please migrate to $apiName instead */
|
|
62
|
+
readonly __apiName: "${objectTypeWithLinks.objectType.apiName}" & {${objectTypeWithLinks.linkTypes.map((linkType) => {
|
|
63
|
+
return `/** @deprecated please migrate to pivotTo(${linkType.apiName}) instead */ searchAround${linkType.apiName.charAt(0).toUpperCase() + linkType.apiName.slice(1)}?: never`;
|
|
64
|
+
})}};
|
|
65
|
+
/** @deprecated please migrate to $primaryKey instead */
|
|
66
|
+
readonly __primaryKey: ${wirePropertyTypeV2ToTypeScriptType(objectTypeWithLinks.objectType.properties[objectTypeWithLinks.objectType.primaryKey].dataType)};
|
|
67
|
+
readonly $apiName: "${objectTypeWithLinks.objectType.apiName}";
|
|
68
|
+
readonly $primaryKey: ${wirePropertyTypeV2ToTypeScriptType(objectTypeWithLinks.objectType.properties[objectTypeWithLinks.objectType.primaryKey].dataType)};
|
|
69
|
+
${Object.entries(objectTypeWithLinks.objectType.properties).sort((a, b) => a[0].localeCompare(b[0])).flatMap(([propertyName, propertyDefinition]) => {
|
|
70
|
+
const propertyType = wirePropertyTypeV2ToTypeScriptType(propertyDefinition.dataType);
|
|
71
|
+
const entries = [`${getDescriptionIfPresent(propertyDefinition.description, true)}readonly ${propertyName}: ${propertyType} | undefined`];
|
|
72
|
+
if (isReservedKeyword(propertyName)) {
|
|
73
|
+
entries.push(`/** @deprecated please migrate to '${propertyName}' instead */
|
|
74
|
+
readonly ${propertyName}_: ${propertyType} | undefined`);
|
|
75
|
+
}
|
|
76
|
+
return entries;
|
|
77
|
+
}).join(";\n")}
|
|
78
|
+
${objectTypeWithLinks.linkTypes.flatMap((linkType) => {
|
|
79
|
+
const entries = [`readonly ${linkType.apiName}: ${linkType.cardinality === "MANY" ? "MultiLink" : "SingleLink"}<${linkType.objectTypeApiName}>`];
|
|
80
|
+
return entries;
|
|
81
|
+
}).join(";\n")}
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
function wirePropertyTypeV2ToTypeScriptType(property) {
|
|
86
|
+
switch (property.type) {
|
|
87
|
+
case "string":
|
|
88
|
+
return "string";
|
|
89
|
+
case "boolean":
|
|
90
|
+
return "boolean";
|
|
91
|
+
case "array":
|
|
92
|
+
return wirePropertyTypeV2ToTypeScriptType(property.subType) + "[]";
|
|
93
|
+
case "integer":
|
|
94
|
+
return "number";
|
|
95
|
+
case "attachment":
|
|
96
|
+
return "Attachment";
|
|
97
|
+
case "byte":
|
|
98
|
+
return "number";
|
|
99
|
+
case "date":
|
|
100
|
+
return "LocalDate";
|
|
101
|
+
case "decimal":
|
|
102
|
+
return "string";
|
|
103
|
+
case "double":
|
|
104
|
+
return "number";
|
|
105
|
+
case "float":
|
|
106
|
+
return "number";
|
|
107
|
+
case "geopoint":
|
|
108
|
+
return "GeoPoint";
|
|
109
|
+
case "geoshape":
|
|
110
|
+
return "GeoShape";
|
|
111
|
+
case "long":
|
|
112
|
+
return "string";
|
|
113
|
+
case "short":
|
|
114
|
+
return "number";
|
|
115
|
+
case "timestamp":
|
|
116
|
+
return "Timestamp";
|
|
117
|
+
case "timeseries":
|
|
118
|
+
return property.itemType.type === "string" ? `TimeSeries<string>` : `TimeSeries<number>`;
|
|
119
|
+
case "marking":
|
|
120
|
+
return "string";
|
|
121
|
+
default:
|
|
122
|
+
throw new Error(`Unknown property type ${property}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function getDescriptionIfPresent(description, includeNewline) {
|
|
126
|
+
if (description) {
|
|
127
|
+
return `/**
|
|
128
|
+
* ${description}
|
|
129
|
+
*/${includeNewline ? "\n" : ""}`;
|
|
130
|
+
}
|
|
131
|
+
return "";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/shared/getEditedEntities.ts
|
|
135
|
+
function getModifiedEntityTypes(action) {
|
|
136
|
+
const addedObjects = /* @__PURE__ */ new Set();
|
|
137
|
+
const modifiedObjects = /* @__PURE__ */ new Set();
|
|
138
|
+
for (const operation of action.operations) {
|
|
139
|
+
switch (operation.type) {
|
|
140
|
+
case "createObject":
|
|
141
|
+
addedObjects.add(operation.objectTypeApiName);
|
|
142
|
+
break;
|
|
143
|
+
case "modifyObject":
|
|
144
|
+
modifiedObjects.add(operation.objectTypeApiName);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
addedObjects,
|
|
150
|
+
modifiedObjects
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/shared/wireActionTypeV2ToSdkActionDefinition.ts
|
|
155
|
+
function wireActionTypeV2ToSdkActionDefinition(input) {
|
|
156
|
+
const modifiedEntityTypes = getModifiedEntityTypes(input);
|
|
157
|
+
return {
|
|
158
|
+
type: "action",
|
|
159
|
+
apiName: input.apiName,
|
|
160
|
+
parameters: Object.fromEntries(Object.entries(input.parameters).map(([key, value]) => [key, wireActionParameterV2ToSdkParameterDefinition(value)])),
|
|
161
|
+
displayName: input.displayName,
|
|
162
|
+
description: input.description,
|
|
163
|
+
modifiedEntities: createModifiedEntities(modifiedEntityTypes.addedObjects, modifiedEntityTypes.modifiedObjects)
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function wireActionParameterV2ToSdkParameterDefinition(value) {
|
|
167
|
+
return {
|
|
168
|
+
multiplicity: value.dataType.type === "array",
|
|
169
|
+
type: actionPropertyToSdkPropertyDefinition(value.dataType.type === "array" ? value.dataType.subType : value.dataType),
|
|
170
|
+
nullable: !value.required,
|
|
171
|
+
description: value.description
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function actionPropertyToSdkPropertyDefinition(parameterType) {
|
|
175
|
+
switch (parameterType.type) {
|
|
176
|
+
case "string":
|
|
177
|
+
case "boolean":
|
|
178
|
+
case "attachment":
|
|
179
|
+
case "double":
|
|
180
|
+
case "integer":
|
|
181
|
+
case "long":
|
|
182
|
+
case "timestamp":
|
|
183
|
+
case "marking":
|
|
184
|
+
return parameterType.type;
|
|
185
|
+
case "date":
|
|
186
|
+
return "datetime";
|
|
187
|
+
case "objectSet":
|
|
188
|
+
return {
|
|
189
|
+
type: "objectSet",
|
|
190
|
+
objectSet: parameterType.objectTypeApiName
|
|
191
|
+
};
|
|
192
|
+
case "object":
|
|
193
|
+
return {
|
|
194
|
+
type: "object",
|
|
195
|
+
object: parameterType.objectTypeApiName
|
|
196
|
+
};
|
|
197
|
+
case "array":
|
|
198
|
+
return actionPropertyToSdkPropertyDefinition(parameterType.subType);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function createModifiedEntities(addedObjects, modifiedObjects) {
|
|
202
|
+
let entities = {};
|
|
203
|
+
for (const key of addedObjects) {
|
|
204
|
+
entities[key] = {
|
|
205
|
+
created: true,
|
|
206
|
+
modified: false
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
for (const key of modifiedObjects) {
|
|
210
|
+
if (entities[key]) {
|
|
211
|
+
entities[key].modified = true;
|
|
212
|
+
} else {
|
|
213
|
+
entities[key] = {
|
|
214
|
+
created: false,
|
|
215
|
+
modified: true
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return entities;
|
|
220
|
+
}
|
|
221
|
+
function getObjectDefIdentifier(name, v2) {
|
|
222
|
+
return v2 ? name : `${name}Def`;
|
|
223
|
+
}
|
|
224
|
+
function wireObjectTypeV2ToSdkObjectConst(object, importExt, v2 = false) {
|
|
225
|
+
const uniqueLinkTargetTypes = new Set(object.linkTypes.map((a) => a.objectTypeApiName));
|
|
226
|
+
const definition = deleteUndefineds(wireObjectTypeFullMetadataToSdkObjectTypeDefinition(object, v2));
|
|
227
|
+
const objectDefIdentifier = getObjectDefIdentifier(object.objectType.apiName, v2);
|
|
228
|
+
function getV1Types() {
|
|
229
|
+
return `
|
|
230
|
+
export interface ${objectDefIdentifier} extends ObjectTypeDefinition<"${object.objectType.apiName}", ${object.objectType.apiName}> {
|
|
231
|
+
${stringify(definition, {
|
|
232
|
+
osdkMetadata: () => void 0,
|
|
233
|
+
// not used in v1
|
|
234
|
+
links: (_value) => `{
|
|
235
|
+
${stringify(definition.links, {
|
|
236
|
+
"*": (definition2) => `ObjectTypeLinkDefinition<${getObjectDefIdentifier(definition2.targetType, v2)}, ${definition2.multiplicity}>`
|
|
237
|
+
})}
|
|
238
|
+
}`
|
|
239
|
+
})}
|
|
240
|
+
}
|
|
241
|
+
`;
|
|
242
|
+
}
|
|
243
|
+
function getV2Types() {
|
|
244
|
+
return `
|
|
245
|
+
export interface ${objectDefIdentifier} extends ObjectTypeDefinition<"${object.objectType.apiName}", ${object.objectType.apiName}>, VersionBound<$ExpectedClientVersion> {
|
|
246
|
+
osdkMetadata: typeof $osdkMetadata;
|
|
247
|
+
${stringify(definition, {
|
|
248
|
+
osdkMetadata: () => void 0,
|
|
249
|
+
// we are going to reference another object instead
|
|
250
|
+
type: () => void 0,
|
|
251
|
+
apiName: () => void 0,
|
|
252
|
+
links: (_value) => `{
|
|
253
|
+
${stringify(definition.links, {
|
|
254
|
+
"*": (definition2) => `ObjectTypeLinkDefinition<${getObjectDefIdentifier(definition2.targetType, v2)}, ${definition2.multiplicity}>`
|
|
255
|
+
})}
|
|
256
|
+
}`,
|
|
257
|
+
properties: (_value) => `{
|
|
258
|
+
${stringify(definition.properties, {
|
|
259
|
+
"*": (propertyDefinition) => `PropertyDef<"${propertyDefinition.type}", "${propertyDefinition.nullable ? "nullable" : "non-nullable"}", "${propertyDefinition.multiplicity ? "array" : "single"}">`
|
|
260
|
+
})}
|
|
261
|
+
}`
|
|
262
|
+
})}
|
|
263
|
+
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
`;
|
|
267
|
+
}
|
|
268
|
+
const imports = Array.from(uniqueLinkTargetTypes).filter((type) => type !== definition.apiName).map((type) => `import type { ${getObjectDefIdentifier(type, v2)} } from "./${type}${importExt}";`);
|
|
269
|
+
return `${imports.join("\n")}
|
|
270
|
+
|
|
271
|
+
${v2 ? getV2Types() : getV1Types()}
|
|
272
|
+
|
|
273
|
+
export const ${object.objectType.apiName}: ${objectDefIdentifier} = {
|
|
274
|
+
${v2 ? `osdkMetadata: $osdkMetadata,` : ""}
|
|
275
|
+
${stringify(definition, {
|
|
276
|
+
osdkMetadata: (value) => void 0
|
|
277
|
+
})}
|
|
278
|
+
|
|
279
|
+
};`;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// src/shared/generatePerActionDataFiles.ts
|
|
283
|
+
async function generatePerActionDataFiles(ontology, fs2, outDir, importExt, v2) {
|
|
284
|
+
await fs2.mkdir(outDir, {
|
|
285
|
+
recursive: true
|
|
286
|
+
});
|
|
287
|
+
await Promise.all(Object.values(ontology.actionTypes).map(async (action) => {
|
|
288
|
+
const uniqueApiNames = new Set(extractReferencedObjectsFromAction(action));
|
|
289
|
+
const uniqueApiNamesString = uniqueApiNames.size > 0 ? [...uniqueApiNames].map((apiName) => `"${apiName}"`).join("|") : "never";
|
|
290
|
+
const fullActionDef = deleteUndefineds(wireActionTypeV2ToSdkActionDefinition(action));
|
|
291
|
+
const {
|
|
292
|
+
parameters,
|
|
293
|
+
...actionDefSansParameters
|
|
294
|
+
} = fullActionDef;
|
|
295
|
+
const actionDefIdentifier = `ActionDef$${action.apiName}`;
|
|
296
|
+
const paramsDefIdentifier = `${actionDefIdentifier}$Params`;
|
|
297
|
+
const paramsIdentifier = `${action.apiName}$Params`;
|
|
298
|
+
function createParamsDef() {
|
|
299
|
+
const entries = Object.entries(parameters);
|
|
300
|
+
entries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
301
|
+
if (entries.length === 0) {
|
|
302
|
+
return `// Represents the definition of the parameters for the action
|
|
303
|
+
export type ${paramsDefIdentifier} = Record<string, never>;`;
|
|
304
|
+
}
|
|
305
|
+
return `// Represents the definition of the parameters for the action
|
|
306
|
+
export type ${paramsDefIdentifier} = {
|
|
307
|
+
${entries.map(([key, value]) => {
|
|
308
|
+
return `"${key}": {
|
|
309
|
+
${stringify(value, {
|
|
310
|
+
description: (value2, d) => value2 ? d(value2) : void 0,
|
|
311
|
+
// trick to remove undefineds
|
|
312
|
+
type: (type) => {
|
|
313
|
+
if (typeof type === "string") {
|
|
314
|
+
return JSON.stringify(type);
|
|
315
|
+
} else if (type.type === "object") {
|
|
316
|
+
return `ObjectActionDataType<"${type.object}", ${getObjectDefIdentifier(type.object, v2)}>`;
|
|
317
|
+
} else if (type.type === "objectSet") {
|
|
318
|
+
return `ObjectSetActionDataType<"${type.objectSet}", ${getObjectDefIdentifier(type.objectSet, v2)}>`;
|
|
319
|
+
}
|
|
320
|
+
return void 0;
|
|
321
|
+
}
|
|
322
|
+
})}
|
|
323
|
+
}`;
|
|
324
|
+
}).join(";\n")}
|
|
325
|
+
}`;
|
|
326
|
+
}
|
|
327
|
+
function createV2Types() {
|
|
328
|
+
return `
|
|
329
|
+
|
|
330
|
+
${createParamsDef()}
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
// Represents the runtime arguments for the action
|
|
334
|
+
export type ${paramsIdentifier} = NOOP<OsdkActionParameters<${paramsDefIdentifier}>>;
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
// Represents a fqn of the action
|
|
338
|
+
export interface ${action.apiName} {
|
|
339
|
+
${getDescriptionIfPresent(action.description)}
|
|
340
|
+
<OP extends ApplyActionOptions>(args: ${paramsIdentifier}, options?: OP): Promise<ActionReturnTypeForOptions<OP>>;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
// Represents the definition of the action
|
|
345
|
+
export interface ${actionDefIdentifier} extends ActionDefinition<"${action.apiName}", ${uniqueApiNamesString}, ${action.apiName}>{
|
|
346
|
+
${Object.entries(actionDefSansParameters).sort((a, b) => a[0].localeCompare(b[0])).map(([key, value]) => {
|
|
347
|
+
return `${key}: ${JSON.stringify(value)};`;
|
|
348
|
+
}).join("\n")}
|
|
349
|
+
parameters: ${paramsDefIdentifier};
|
|
350
|
+
osdkMetadata: typeof $osdkMetadata;
|
|
351
|
+
}`;
|
|
352
|
+
}
|
|
353
|
+
function createV2Object() {
|
|
354
|
+
return ` export const ${action.apiName}: ${actionDefIdentifier} =
|
|
355
|
+
{
|
|
356
|
+
${stringify(fullActionDef)},
|
|
357
|
+
osdkMetadata: $osdkMetadata
|
|
358
|
+
}
|
|
359
|
+
`;
|
|
360
|
+
}
|
|
361
|
+
function createV1Object() {
|
|
362
|
+
return ` export const ${action.apiName} = ${JSON.stringify(fullActionDef, null, 2)} satisfies ActionDefinition<"${action.apiName}", ${uniqueApiNamesString}>;`;
|
|
363
|
+
}
|
|
364
|
+
const referencedObjectDefs = /* @__PURE__ */ new Set();
|
|
365
|
+
for (const p of Object.values(action.parameters)) {
|
|
366
|
+
if (p.dataType.type === "object" || p.dataType.type === "objectSet") {
|
|
367
|
+
referencedObjectDefs.add(getObjectDefIdentifier(p.dataType.objectApiName, v2));
|
|
368
|
+
referencedObjectDefs.add(getObjectDefIdentifier(p.dataType.objectTypeApiName, v2));
|
|
369
|
+
}
|
|
370
|
+
if (p.dataType.type === "array" && (p.dataType.subType.type === "object" || p.dataType.subType.type === "objectSet")) {
|
|
371
|
+
referencedObjectDefs.add(getObjectDefIdentifier(p.dataType.subType.objectApiName, v2));
|
|
372
|
+
referencedObjectDefs.add(getObjectDefIdentifier(p.dataType.subType.objectTypeApiName, v2));
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const importObjects = referencedObjectDefs.size > 0 ? `import type {${[...referencedObjectDefs].join(",")}} from "../objects${importExt}";` : "";
|
|
376
|
+
await fs2.writeFile(path16__default.join(outDir, `${action.apiName}.ts`), await formatTs(`
|
|
377
|
+
import type { ActionDefinition, ObjectActionDataType, ObjectSetActionDataType } from "@osdk/api";
|
|
378
|
+
import type { ActionSignature, ApplyActionOptions, OsdkActionParameters,ActionReturnTypeForOptions, NOOP } from '@osdk/client';
|
|
379
|
+
import { $osdkMetadata} from "../../OntologyMetadata${importExt}";
|
|
380
|
+
${importObjects}
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
${v2 ? createV2Types() : ""}
|
|
384
|
+
|
|
385
|
+
${v2 ? createV2Object() : createV1Object()}
|
|
386
|
+
`));
|
|
387
|
+
}));
|
|
388
|
+
await fs2.writeFile(path16__default.join(outDir, `index.ts`), await formatTs(`
|
|
389
|
+
${Object.values(ontology.actionTypes).map((action) => `export {${action.apiName}} from "./${action.apiName}${importExt}";`).join("\n")}
|
|
390
|
+
${Object.keys(ontology.actionTypes).length === 0 ? "export {};" : ""}
|
|
391
|
+
`));
|
|
392
|
+
}
|
|
393
|
+
function extractReferencedObjectsFromAction(actionType) {
|
|
394
|
+
const referencedObjectsInParameters = Object.values(actionType.parameters).flatMap(({
|
|
395
|
+
dataType
|
|
396
|
+
}) => {
|
|
397
|
+
const objectTypeReference = extractReferencedObjectsFromActionParameter(dataType);
|
|
398
|
+
return objectTypeReference ? [objectTypeReference] : [];
|
|
399
|
+
});
|
|
400
|
+
const referenceObjectsInEdits = actionType.operations.flatMap((value) => {
|
|
401
|
+
switch (value.type) {
|
|
402
|
+
case "createObject":
|
|
403
|
+
return [value.objectTypeApiName];
|
|
404
|
+
case "modifyObject":
|
|
405
|
+
return [value.objectTypeApiName];
|
|
406
|
+
case "deleteObject":
|
|
407
|
+
case "createLink":
|
|
408
|
+
case "deleteLink":
|
|
409
|
+
return [];
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
return [...referenceObjectsInEdits, ...referencedObjectsInParameters];
|
|
413
|
+
}
|
|
414
|
+
function extractReferencedObjectsFromActionParameter(actionParameter) {
|
|
415
|
+
switch (actionParameter.type) {
|
|
416
|
+
case "objectSet":
|
|
417
|
+
case "object":
|
|
418
|
+
return actionParameter.objectTypeApiName;
|
|
419
|
+
case "array":
|
|
420
|
+
return extractReferencedObjectsFromActionParameter(actionParameter.subType);
|
|
421
|
+
case "string":
|
|
422
|
+
case "boolean":
|
|
423
|
+
case "attachment":
|
|
424
|
+
case "date":
|
|
425
|
+
case "double":
|
|
426
|
+
case "integer":
|
|
427
|
+
case "long":
|
|
428
|
+
case "timestamp":
|
|
429
|
+
return void 0;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/shared/sanitizeMetadata.ts
|
|
434
|
+
function sanitizeMetadata(ontology) {
|
|
435
|
+
return {
|
|
436
|
+
...ontology,
|
|
437
|
+
actionTypes: Object.fromEntries(Object.values(ontology.actionTypes).map((actionType) => {
|
|
438
|
+
return [camelize(actionType.apiName), {
|
|
439
|
+
...actionType,
|
|
440
|
+
apiName: camelize(actionType.apiName)
|
|
441
|
+
}];
|
|
442
|
+
}))
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
function camelize(name) {
|
|
446
|
+
return name.replace(/-./g, (segment) => segment[1].toUpperCase());
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// src/util/verifyOutdir.ts
|
|
450
|
+
async function verifyOutdir(outDir, fs2) {
|
|
451
|
+
try {
|
|
452
|
+
const contents = await fs2.readdir(outDir);
|
|
453
|
+
if (contents.length !== 0) {
|
|
454
|
+
throw new Error(`outDir ${outDir} is not empty, please delete its contents and try again`);
|
|
455
|
+
}
|
|
456
|
+
} catch (e) {
|
|
457
|
+
if (e.code === "ENOENT") ; else {
|
|
458
|
+
throw e;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
async function generateActions(ontology, fs2, outDir, importExt = "") {
|
|
463
|
+
const importedObjects = /* @__PURE__ */ new Set();
|
|
464
|
+
let actionSignatures = [];
|
|
465
|
+
for (const action of Object.values(ontology.actionTypes)) {
|
|
466
|
+
const entries = Object.entries(action.parameters);
|
|
467
|
+
const modifiedEntityTypes = getModifiedEntityTypes(action);
|
|
468
|
+
const addedObjects = Array.from(modifiedEntityTypes.addedObjects);
|
|
469
|
+
const modifiedObjects = Array.from(modifiedEntityTypes.modifiedObjects);
|
|
470
|
+
addedObjects.forEach(importedObjects.add, importedObjects);
|
|
471
|
+
modifiedObjects.forEach(importedObjects.add, importedObjects);
|
|
472
|
+
let jsDocBlock = ["/**"];
|
|
473
|
+
if (action.description) {
|
|
474
|
+
jsDocBlock.push(`* ${action.description}`);
|
|
475
|
+
}
|
|
476
|
+
let parameterBlock = "";
|
|
477
|
+
if (entries.length > 0) {
|
|
478
|
+
parameterBlock = `params: {
|
|
479
|
+
`;
|
|
480
|
+
for (const [parameterName, parameterData] of entries) {
|
|
481
|
+
parameterBlock += `"${parameterName}"`;
|
|
482
|
+
parameterBlock += parameterData.required ? ": " : "?: ";
|
|
483
|
+
const typeScriptType = getTypeScriptTypeFromDataType(parameterData.dataType, importedObjects);
|
|
484
|
+
parameterBlock += `${typeScriptType};
|
|
485
|
+
`;
|
|
486
|
+
jsDocBlock.push(`* @param {${typeScriptType}} params.${parameterName}`);
|
|
487
|
+
}
|
|
488
|
+
parameterBlock += "}, ";
|
|
489
|
+
}
|
|
490
|
+
jsDocBlock.push(`*/`);
|
|
491
|
+
actionSignatures.push(`
|
|
492
|
+
${jsDocBlock.join("\n")}
|
|
493
|
+
${action.apiName}<O extends ActionExecutionOptions>(${parameterBlock}options?: O):
|
|
494
|
+
Promise<Result<ActionResponseFromOptions<O, Edits<${addedObjects.length > 0 ? addedObjects.join(" | ") : "void"}, ${modifiedObjects.length > 0 ? modifiedObjects.join(" | ") : "void"}>>, ActionError>>;`);
|
|
495
|
+
}
|
|
496
|
+
await fs2.mkdir(outDir, {
|
|
497
|
+
recursive: true
|
|
498
|
+
});
|
|
499
|
+
await fs2.writeFile(path16__default.join(outDir, "Actions.ts"), await formatTs(`
|
|
500
|
+
import type { ObjectSet, LocalDate, Timestamp, Attachment, Edits, ActionExecutionOptions, ActionError, Result, ActionResponseFromOptions } from "@osdk/legacy-client";
|
|
501
|
+
${Array.from(importedObjects).map((importedObject) => `import type { ${importedObject} } from "../objects/${importedObject}${importExt}";`).join("\n")}
|
|
502
|
+
export interface Actions {
|
|
503
|
+
${actionSignatures.join("\n")}
|
|
504
|
+
}
|
|
505
|
+
`));
|
|
506
|
+
}
|
|
507
|
+
function getTypeScriptTypeFromDataType(actionParameter, importedObjects) {
|
|
508
|
+
switch (actionParameter.type) {
|
|
509
|
+
case "objectSet": {
|
|
510
|
+
const objectType = actionParameter.objectTypeApiName;
|
|
511
|
+
importedObjects.add(objectType);
|
|
512
|
+
return `ObjectSet<${objectType}>`;
|
|
513
|
+
}
|
|
514
|
+
case "object": {
|
|
515
|
+
const objectType = actionParameter.objectTypeApiName;
|
|
516
|
+
importedObjects.add(objectType);
|
|
517
|
+
return `${objectType} | ${objectType}["__primaryKey"]`;
|
|
518
|
+
}
|
|
519
|
+
case "array":
|
|
520
|
+
return `Array<${getTypeScriptTypeFromDataType(actionParameter.subType, importedObjects)}>`;
|
|
521
|
+
case "string":
|
|
522
|
+
return `string`;
|
|
523
|
+
case "boolean":
|
|
524
|
+
return `boolean`;
|
|
525
|
+
case "attachment":
|
|
526
|
+
return `Attachment`;
|
|
527
|
+
case "date":
|
|
528
|
+
return `LocalDate`;
|
|
529
|
+
case "double":
|
|
530
|
+
case "integer":
|
|
531
|
+
case "long":
|
|
532
|
+
return `number`;
|
|
533
|
+
case "timestamp":
|
|
534
|
+
return `Timestamp`;
|
|
535
|
+
case "marking":
|
|
536
|
+
return "string";
|
|
537
|
+
default:
|
|
538
|
+
throw new Error(`Unsupported action parameter type: ${actionParameter}`);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/v1.1/backcompat/util/reexportConsts.ts
|
|
543
|
+
function reexportConsts(typesToExport) {
|
|
544
|
+
return `
|
|
545
|
+
import { ${typesToExport.map((q) => `${q} as OG_${q}`).join(", ")}} from "@osdk/legacy-client";
|
|
546
|
+
|
|
547
|
+
${typesToExport.map((q) => `
|
|
548
|
+
/** @deprecated submodule imports arent public api **/
|
|
549
|
+
export const ${q} = OG_${q};
|
|
550
|
+
`).join("\n\n")}
|
|
551
|
+
`;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// src/v1.1/backcompat/internal-foundry-oauth-dist/generateConfidentialClientDir.ts
|
|
555
|
+
async function generateConfidentialClientDir(fs2, oauthDistDir, importExt = "") {
|
|
556
|
+
const confidentialClientDistDir = path16__default.join(oauthDistDir, "ConfidentialClient");
|
|
557
|
+
await fs2.mkdir(confidentialClientDistDir, {
|
|
558
|
+
recursive: true
|
|
559
|
+
});
|
|
560
|
+
await fs2.writeFile(path16__default.join(confidentialClientDistDir, "index.ts"), await formatTs(`
|
|
561
|
+
export * from "./ConfidentialClientAuth${importExt}";
|
|
562
|
+
`));
|
|
563
|
+
await fs2.writeFile(path16__default.join(confidentialClientDistDir, "ConfidentialClientAuth.ts"), await formatTs(`
|
|
564
|
+
${reexportConsts(["ConfidentialClientAuth"])}
|
|
565
|
+
`));
|
|
566
|
+
}
|
|
567
|
+
async function generatePublicClientDir(fs2, oauthDistDir, importExt = "") {
|
|
568
|
+
const publicClientDistDir = path16__default.join(oauthDistDir, "PublicClient");
|
|
569
|
+
await fs2.mkdir(publicClientDistDir, {
|
|
570
|
+
recursive: true
|
|
571
|
+
});
|
|
572
|
+
await fs2.writeFile(path16__default.join(publicClientDistDir, "index.ts"), await formatTs(`
|
|
573
|
+
export * from "./PublicClientAuth${importExt}";
|
|
574
|
+
`));
|
|
575
|
+
await fs2.writeFile(path16__default.join(publicClientDistDir, "PublicClientAuth.ts"), await formatTs(`
|
|
576
|
+
${reexportConsts(["PublicClientAuth"])}
|
|
577
|
+
`));
|
|
578
|
+
}
|
|
579
|
+
async function generateUserTokenDir(fs2, oauthDistDir, importExt = "") {
|
|
580
|
+
const userTokenDistDir = path16__default.join(oauthDistDir, "UserToken");
|
|
581
|
+
await fs2.mkdir(userTokenDistDir, {
|
|
582
|
+
recursive: true
|
|
583
|
+
});
|
|
584
|
+
await fs2.writeFile(path16__default.join(userTokenDistDir, "index.ts"), await formatTs(`
|
|
585
|
+
export * from "./UserTokenAuth${importExt}";
|
|
586
|
+
`));
|
|
587
|
+
await fs2.writeFile(path16__default.join(userTokenDistDir, "UserTokenAuth.ts"), await formatTs(`
|
|
588
|
+
${reexportConsts(["UserTokenAuth"])}
|
|
589
|
+
`));
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// src/v1.1/backcompat/util/reexportTypes.ts
|
|
593
|
+
function reexportTypes(typesToExport, genericArgsLeft = "", genericArgsRight = cleanup(genericArgsLeft)) {
|
|
594
|
+
return `
|
|
595
|
+
import type { ${typesToExport.map((q) => `${q} as OG_${q}`).join(", ")}} from "@osdk/legacy-client";
|
|
596
|
+
|
|
597
|
+
${typesToExport.map((q) => `
|
|
598
|
+
/** @deprecated submodule imports arent public api **/
|
|
599
|
+
export type ${q}${genericArgsLeft} = OG_${q}${genericArgsRight};
|
|
600
|
+
`).join("\n\n")}
|
|
601
|
+
`;
|
|
602
|
+
}
|
|
603
|
+
var captureInBracketsRegex = /<(.*?)>/;
|
|
604
|
+
var captureGenericParamNameRegex = /^\s?(.+?)( extends .*?)?( = .*?)?\s?$/;
|
|
605
|
+
function cleanup(s) {
|
|
606
|
+
if (s.length === 0)
|
|
607
|
+
return "";
|
|
608
|
+
const genericParameterNames = captureInBracketsRegex.exec(s)?.[1]?.split(",")?.map((a) => {
|
|
609
|
+
return captureGenericParamNameRegex.exec(a)?.[1] ?? a;
|
|
610
|
+
});
|
|
611
|
+
return `<${genericParameterNames?.join(",")}>`;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// src/v1.1/backcompat/generateOAuthDistDir.ts
|
|
615
|
+
async function generateOAuthClientDistDir(outDir, fs2, importExt = "") {
|
|
616
|
+
const oauthDistDir = path16.join(outDir, "internal", "@foundry", "oauth-client", "dist");
|
|
617
|
+
await fs2.mkdir(oauthDistDir, {
|
|
618
|
+
recursive: true
|
|
619
|
+
});
|
|
620
|
+
await fs2.writeFile(path16.join(oauthDistDir, "index.ts"), await formatTs(`
|
|
621
|
+
export * from "./Auth${importExt}";
|
|
622
|
+
export * from "./ConfidentialClient/index${importExt}";
|
|
623
|
+
export * from "./OAuthClient${importExt}";
|
|
624
|
+
export * from "./PublicClient/index${importExt}";
|
|
625
|
+
export * from "./Token${importExt}";
|
|
626
|
+
export * from "./UserToken/index${importExt}";
|
|
627
|
+
`));
|
|
628
|
+
await fs2.writeFile(path16.join(oauthDistDir, "Auth.ts"), await formatTs(reexportTypes(["Auth"])));
|
|
629
|
+
await fs2.writeFile(path16.join(oauthDistDir, "Token.ts"), await formatTs(reexportTypes(["Token", "TokenValue"])));
|
|
630
|
+
await fs2.writeFile(path16.join(oauthDistDir, "OAuthClient.ts"), await formatTs(reexportTypes(["AuthSubscription", "UnsubscribeFunction", "SignInResponse", "RefreshResponse", "SignOutResponse"])));
|
|
631
|
+
await fs2.writeFile(path16.join(oauthDistDir, "OAuthToken.ts"), await formatTs(reexportConsts(["OAuthToken"])));
|
|
632
|
+
await fs2.writeFile(path16.join(oauthDistDir, "Auth.ts"), await formatTs(reexportTypes(["Auth"])));
|
|
633
|
+
await generateConfidentialClientDir(fs2, oauthDistDir, importExt);
|
|
634
|
+
await generatePublicClientDir(fs2, oauthDistDir, importExt);
|
|
635
|
+
await generateUserTokenDir(fs2, oauthDistDir, importExt);
|
|
636
|
+
}
|
|
637
|
+
async function generateAggregationsAggregations(fs2, aggregationsDir) {
|
|
638
|
+
await fs2.writeFile(path16.join(aggregationsDir, "Aggregations.ts"), await formatTs(`
|
|
639
|
+
import { LocalDate, Timestamp } from "@osdk/legacy-client";
|
|
640
|
+
` + 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 = {}>")));
|
|
641
|
+
}
|
|
642
|
+
async function generateGroupBy(fs2, aggregationsDir, importExt = "") {
|
|
643
|
+
await fs2.mkdir(path16.join(aggregationsDir, "groupBy"), {
|
|
644
|
+
recursive: true
|
|
645
|
+
});
|
|
646
|
+
const groupBys = ["BooleanGroupBy", "LocalDateGroupBy", "NumericGroupBy", "StringGroupBy", "TimestampGroupBy"];
|
|
647
|
+
const reexportFiles = [...groupBys, "GroupKeyType"];
|
|
648
|
+
for (const key of reexportFiles) {
|
|
649
|
+
await fs2.writeFile(path16.join(aggregationsDir, "groupBy", `${key}.ts`), await formatTs(`export {${key}} from "./index${importExt}";`));
|
|
650
|
+
}
|
|
651
|
+
await fs2.writeFile(path16.join(aggregationsDir, "groupBy", "index.ts"), await formatTs(`import { Bucketing, BucketKey, Duration, Range, Rangeable } from "../Aggregations${importExt}";` + reexportConsts(groupBys) + reexportTypes(groupBys, "<T extends BucketKey>") + `export {GroupKeyType} from "@osdk/legacy-client";
|
|
652
|
+
`));
|
|
653
|
+
}
|
|
654
|
+
async function generateMetrics(fs2, aggregationsDir, importExt = "") {
|
|
655
|
+
const metricsDir = path16.join(aggregationsDir, "metrics");
|
|
656
|
+
await fs2.mkdir(metricsDir, {
|
|
657
|
+
recursive: true
|
|
658
|
+
});
|
|
659
|
+
await fs2.writeFile(path16.join(metricsDir, "metrics.ts"), await formatTs(`export {MetricValueType} from "@osdk/legacy-client";`));
|
|
660
|
+
await fs2.writeFile(path16.join(metricsDir, "ApproximateDistinctCountAggregatableProperty.ts"), await formatTs(reexportConsts(["ApproximateDistinctCountAggregatableProperty"]) + reexportTypes(["ApproximateDistinctCountAggregatableProperty"])));
|
|
661
|
+
await fs2.writeFile(path16.join(metricsDir, "MultipleAggregatableProperty.ts"), await formatTs(`
|
|
662
|
+
import { Double, MetricValue, MultipleAggregationsOperations } from "../Aggregations${importExt}";
|
|
663
|
+
import { MetricValueType } from "./metrics/index${importExt}";
|
|
664
|
+
` + reexportConsts(["MultipleAggregatableProperty"]) + reexportTypes(["MultipleAggregatableProperty"], "<TResult extends MetricValue = Double>")));
|
|
665
|
+
for (const typeName of ["DefaultAggregatableProperty", "LocalDatePropertyMetric", "NumericPropertyMetric", "TimestampPropertyMetric"]) {
|
|
666
|
+
await fs2.writeFile(path16.join(metricsDir, `${typeName}.ts`), await formatTs(`
|
|
667
|
+
import { MultipleAggregatableProperty } from "./MultipleAggregatableProperty${importExt}";
|
|
668
|
+
` + reexportConsts([typeName])));
|
|
669
|
+
}
|
|
670
|
+
await fs2.writeFile(path16.join(metricsDir, "index.ts"), await formatTs(`
|
|
671
|
+
export * from "./ApproximateDistinctCountAggregatableProperty${importExt}";
|
|
672
|
+
export * from "./DefaultAggregatableProperty${importExt}";
|
|
673
|
+
export * from "./LocalDatePropertyMetric${importExt}";
|
|
674
|
+
export * from "./metrics${importExt}";
|
|
675
|
+
export * from "./MultipleAggregatableProperty${importExt}";
|
|
676
|
+
export * from "./NumericPropertyMetric${importExt}";
|
|
677
|
+
export * from "./TimestampPropertyMetric${importExt}";
|
|
678
|
+
`));
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// src/v1.1/backcompat/internal-foundry-ontology-runtime-dist/generateAggregationsDir.ts
|
|
682
|
+
async function generateAggregationsDir(fs2, runtimeDistDir, importExt = "") {
|
|
683
|
+
const aggregationsDir = path16.join(runtimeDistDir, "aggregations");
|
|
684
|
+
await fs2.mkdir(aggregationsDir, {
|
|
685
|
+
recursive: true
|
|
686
|
+
});
|
|
687
|
+
await generateGroupBy(fs2, aggregationsDir, importExt);
|
|
688
|
+
await generateAggregationsAggregations(fs2, aggregationsDir);
|
|
689
|
+
await generateMetrics(fs2, aggregationsDir, importExt);
|
|
690
|
+
await fs2.writeFile(path16.join(aggregationsDir, "index.ts"), await formatTs(`
|
|
691
|
+
${""}
|
|
692
|
+
${""}
|
|
693
|
+
|
|
694
|
+
export * from "./Aggregations${importExt}";
|
|
695
|
+
export * from "./ComputeStep${importExt}";
|
|
696
|
+
export * from "./CountOperation${importExt}";
|
|
697
|
+
export * from "./groupBy/index${importExt}";
|
|
698
|
+
export * from "./internalAggregationRequest${importExt}";
|
|
699
|
+
export * from "./metrics/index${importExt}";
|
|
700
|
+
`));
|
|
701
|
+
await fs2.writeFile(path16.join(aggregationsDir, "ComputeStep.ts"), await formatTs(`
|
|
702
|
+
import { ObjectSetDefinition } from "../baseTypes/index${importExt}";
|
|
703
|
+
import { FoundryClientOptions } from "../client/${importExt}";
|
|
704
|
+
import { AggregateObjectsError, OntologyMetadata, Result } from "../ontologyProvider/index${importExt}";
|
|
705
|
+
import { AggregationClause, AggregationResult, BucketGroup, BucketValue, InternalBucketing, Metrics, MetricValue } from "./Aggregations${importExt}";
|
|
706
|
+
` + reexportConsts(["ComputeStep"]) + reexportTypes(["ComputeStep"], "<TBucketGroup extends BucketGroup, TMetrics extends Metrics | MetricValue> ") + reexportTypes(["AggregationComputeStep"], "<TBucketGroup extends BucketGroup, TMetrics extends Metrics | MetricValue>") + `
|
|
707
|
+
|
|
708
|
+
`));
|
|
709
|
+
await fs2.writeFile(path16.join(aggregationsDir, "CountOperation.ts"), await formatTs(`` + reexportConsts(["CountOperation", "isCountOperation"]) + reexportTypes(["CountOperation"])));
|
|
710
|
+
await fs2.writeFile(path16.join(aggregationsDir, "internalAggregationRequest.ts"), await formatTs(reexportTypes(["InternalAggregationRequest"])));
|
|
711
|
+
}
|
|
712
|
+
async function generateAttachmentsDir(attachmentsDir, fs2, importExt = "") {
|
|
713
|
+
await fs2.mkdir(attachmentsDir, {
|
|
714
|
+
recursive: true
|
|
715
|
+
});
|
|
716
|
+
await fs2.writeFile(path16__default.join(attachmentsDir, "index.ts"), await formatTs(`export * from "./Attachment${importExt}";
|
|
717
|
+
export * from "./Attachments${importExt}";
|
|
718
|
+
`));
|
|
719
|
+
await fs2.writeFile(path16__default.join(attachmentsDir, "Attachment.ts"), await formatTs(reexportTypes(["Attachment", "AttachmentMetadata"])));
|
|
720
|
+
await fs2.writeFile(path16__default.join(attachmentsDir, "Attachments.ts"), await formatTs(reexportTypes(["Attachments"])));
|
|
721
|
+
}
|
|
722
|
+
async function generateGeoshapesDir(runtimeDistDir, fs2, importExt = "") {
|
|
723
|
+
await fs2.mkdir(runtimeDistDir, {
|
|
724
|
+
recursive: true
|
|
725
|
+
});
|
|
726
|
+
await fs2.writeFile(path16.join(runtimeDistDir, "index.ts"), await formatTs(`export * from "./Distance${importExt}";
|
|
727
|
+
export * from "./GeoJson${importExt}";
|
|
728
|
+
export * from "./GeometryCollection${importExt}";
|
|
729
|
+
export * from "./GeoPoint${importExt}";
|
|
730
|
+
export * from "./GeoShape${importExt}";
|
|
731
|
+
export * from "./LineString${importExt}";
|
|
732
|
+
export * from "./MultiGeoPoint${importExt}";
|
|
733
|
+
export * from "./MultiLineString${importExt}";
|
|
734
|
+
export * from "./MultiPolygon${importExt}";
|
|
735
|
+
export * from "./Polygon${importExt}";`));
|
|
736
|
+
await fs2.writeFile(path16.join(runtimeDistDir, "Distance.ts"), await formatTs(`` + reexportConsts(["Distance", "DistanceUnit"]) + reexportTypes(["Distance", "DistanceUnit"])));
|
|
737
|
+
await fs2.writeFile(path16.join(runtimeDistDir, "GeoJson.ts"), await formatTs(reexportTypes(["GeoJsonPoint", "GeoJsonPolygon", "GeoJsonLineString", "GeoJsonMultiPoint", "GeoJsonMultiPolygon", "GeoJsonMultiLineString", "GeoJsonGeometryCollection", "GeoJsonGeometry", "GeoJson"])));
|
|
738
|
+
await fs2.writeFile(path16.join(runtimeDistDir, "GeometryCollection.ts"), await formatTs(reexportConsts(["GeometryCollection"])));
|
|
739
|
+
await fs2.writeFile(path16.join(runtimeDistDir, "GeoPoint.ts"), await formatTs(`` + reexportConsts(["isGeoPoint", "GeoPoint", "mapCoordinatesToGeoPoint"]) + reexportTypes(["GeoHash", "Coordinates", "GeoPoint"])));
|
|
740
|
+
await fs2.writeFile(path16.join(runtimeDistDir, "GeoShape.ts"), await formatTs(reexportConsts(["GeoShape"]) + reexportTypes(["GeoShape"])));
|
|
741
|
+
await fs2.writeFile(path16.join(runtimeDistDir, "LineString.ts"), await formatTs(reexportConsts(["LineString"]) + reexportTypes(["LineString"])));
|
|
742
|
+
await fs2.writeFile(path16.join(runtimeDistDir, "MultiGeoPoint.ts"), await formatTs(reexportConsts(["MultiGeoPoint"]) + reexportTypes(["MultiGeoPoint"])));
|
|
743
|
+
await fs2.writeFile(path16.join(runtimeDistDir, "MultiLineString.ts"), await formatTs(reexportConsts(["MultiLineString"]) + reexportTypes(["MultiLineString"])));
|
|
744
|
+
await fs2.writeFile(path16.join(runtimeDistDir, "MultiPolygon.ts"), await formatTs(reexportConsts(["MultiPolygon"]) + reexportTypes(["MultiPolygon"])));
|
|
745
|
+
await fs2.writeFile(path16.join(runtimeDistDir, "Polygon.ts"), await formatTs(reexportConsts(["Polygon"]) + reexportTypes(["LinearRing", "Polygon"])));
|
|
746
|
+
}
|
|
747
|
+
async function generateObjectSetDir(objectSetDir, fs2, importExt = "") {
|
|
748
|
+
await fs2.mkdir(objectSetDir, {
|
|
749
|
+
recursive: true
|
|
750
|
+
});
|
|
751
|
+
await fs2.writeFile(path16__default.join(objectSetDir, "index.ts"), await formatTs(`
|
|
752
|
+
export * from "./ObjectSetDefinition${importExt}";
|
|
753
|
+
export * from "./OntologyObjectSet${importExt}";
|
|
754
|
+
`));
|
|
755
|
+
await fs2.writeFile(path16__default.join(objectSetDir, "ObjectSetDefinition.ts"), await formatTs(reexportTypes(["BaseObjectSetDefinition", "ReferenceObjectSetDefinition", "StaticObjectSetDefinition", "IntersectObjectSetDefinition", "SubtractObjectSetDefinition", "SearchAroundObjectSetDefinition", "FilterObjectSetDefinition", "ObjectSetDefinition"])));
|
|
756
|
+
await fs2.writeFile(path16__default.join(objectSetDir, "OntologyObjectSet.ts"), await formatTs(reexportTypes(["OntologyObjectSet"])));
|
|
757
|
+
}
|
|
758
|
+
async function generateSharedObjectCodeDir(sharedObjectCodeDir, fs2, importExt = "") {
|
|
759
|
+
await fs2.mkdir(sharedObjectCodeDir, {
|
|
760
|
+
recursive: true
|
|
761
|
+
});
|
|
762
|
+
await fs2.writeFile(path16__default.join(sharedObjectCodeDir, "index.ts"), await formatTs(`
|
|
763
|
+
export * from "./FilteredPropertiesTerminalOperations${importExt}";
|
|
764
|
+
`));
|
|
765
|
+
await fs2.writeFile(path16__default.join(sharedObjectCodeDir, "FilteredPropertiesTerminalOperations.ts"), await formatTs(`import { OntologyObject } from "../OntologyObject${importExt}` + reexportTypes(["FilteredPropertiesTerminalOperations", "FilteredPropertiesTerminalOperationsWithGet"], "<T extends OntologyObject, V extends Array<keyof T>>")));
|
|
766
|
+
}
|
|
767
|
+
async function generateTimeSeriesDir(timeseriesDir, fs2, importExt = "") {
|
|
768
|
+
await fs2.mkdir(timeseriesDir, {
|
|
769
|
+
recursive: true
|
|
770
|
+
});
|
|
771
|
+
await fs2.writeFile(path16.join(timeseriesDir, "index.ts"), await formatTs(`
|
|
772
|
+
export * from "./TimeSeries${importExt}";
|
|
773
|
+
export * from "./TimeSeriesDuration${importExt}";
|
|
774
|
+
export * from "./TimeSeriesPoint${importExt}";
|
|
775
|
+
${""}
|
|
776
|
+
export * from "./TimeSeriesQuery${importExt}";
|
|
777
|
+
export * from "./TimeSeriesTerminalOperations${importExt}";
|
|
778
|
+
`));
|
|
779
|
+
await fs2.writeFile(path16.join(timeseriesDir, "TimeSeries.ts"), await formatTs(reexportTypes(["TimeSeries"], `<T extends number | string>`)));
|
|
780
|
+
await fs2.writeFile(path16.join(timeseriesDir, "TimeSeriesDuration.ts"), await formatTs(reexportTypes([`WhenUnit`, `DurationUnit`, `TimeSeriesDuration`])));
|
|
781
|
+
await fs2.writeFile(path16.join(timeseriesDir, "TimeSeriesPoint.ts"), await formatTs(reexportTypes(["TimeSeriesPoint"], `<T extends number | string>`)));
|
|
782
|
+
await fs2.writeFile(path16.join(timeseriesDir, "TimeSeriesQuery.ts"), await formatTs(reexportTypes(["TimeSeriesQuery"], `<T extends number | string>`)));
|
|
783
|
+
await fs2.writeFile(path16.join(timeseriesDir, "TimeSeriesTerminalOperations.ts"), await formatTs(reexportTypes(["TimeSeriesTerminalOperations", "TimeSeriesIterator"], `<T extends number | string>`)));
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// src/v1.1/backcompat/internal-foundry-ontology-runtime-dist/generateBaseTypesDir.ts
|
|
787
|
+
async function generateBaseTypesDir(runtimeDistDir, fs2, importExt = "") {
|
|
788
|
+
const baseTypesDir = path16.join(runtimeDistDir, "baseTypes");
|
|
789
|
+
await fs2.mkdir(baseTypesDir, {
|
|
790
|
+
recursive: true
|
|
791
|
+
});
|
|
792
|
+
await fs2.writeFile(path16.join(baseTypesDir, "index.ts"), await formatTs(`export * from "./ActionType${importExt}";
|
|
793
|
+
export * from "./attachments/index${importExt}";
|
|
794
|
+
export * from "./geoshapes/index${importExt}";
|
|
795
|
+
export * from "./links${importExt}";
|
|
796
|
+
export * from "./localDate${importExt}";
|
|
797
|
+
export * from "./objectset/index${importExt}";
|
|
798
|
+
export * from "./ObjectType${importExt}";
|
|
799
|
+
export * from "./OntologyObject${importExt}";
|
|
800
|
+
export * from "./Queries${importExt}";
|
|
801
|
+
export * from "./timeseries/index${importExt}";
|
|
802
|
+
export * from "./timestamp${importExt}";`));
|
|
803
|
+
const geoshapesDir = path16.join(baseTypesDir, "geoshapes");
|
|
804
|
+
await generateGeoshapesDir(geoshapesDir, fs2, importExt);
|
|
805
|
+
const timeseriesDir = path16.join(baseTypesDir, "timeseries");
|
|
806
|
+
await generateTimeSeriesDir(timeseriesDir, fs2, importExt);
|
|
807
|
+
const attachmentsDir = path16.join(baseTypesDir, "attachments");
|
|
808
|
+
await generateAttachmentsDir(attachmentsDir, fs2, importExt);
|
|
809
|
+
const objectSetDir = path16.join(baseTypesDir, "objectset");
|
|
810
|
+
await generateObjectSetDir(objectSetDir, fs2, importExt);
|
|
811
|
+
const sharedObjectCodeDir = path16.join(baseTypesDir, "sharedObjectCode");
|
|
812
|
+
await generateSharedObjectCodeDir(sharedObjectCodeDir, fs2, importExt);
|
|
813
|
+
await fs2.writeFile(path16.join(baseTypesDir, "ActionType.ts"), await formatTs(`import { OntologyObject } from "./OntologyObject${importExt}";
|
|
814
|
+
` + 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>")));
|
|
815
|
+
await fs2.writeFile(path16.join(baseTypesDir, "OntologyObject.ts"), await formatTs(reexportTypes(["OntologyObject"]) + reexportConsts(["isOntologyObject"])));
|
|
816
|
+
await fs2.writeFile(path16.join(baseTypesDir, "links.ts"), await formatTs(`import { OntologyObject } from "./OntologyObject${importExt}` + reexportTypes(["SingleLink", "MultiLink"], "<T extends OntologyObject = OntologyObject>")));
|
|
817
|
+
await fs2.writeFile(path16.join(baseTypesDir, "localDate.ts"), await formatTs(reexportConsts(["LocalDate"]) + reexportTypes(["LocalDate"])));
|
|
818
|
+
await fs2.writeFile(path16.join(baseTypesDir, "timestamp.ts"), await formatTs(reexportConsts(["Timestamp"]) + reexportTypes(["Timestamp"])));
|
|
819
|
+
await fs2.writeFile(path16.join(baseTypesDir, "Queries.ts"), await formatTs(`import { BucketValue, Range, Rangeable } from "../aggregations/index${importExt}";
|
|
820
|
+
` + 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"])));
|
|
821
|
+
await fs2.writeFile(path16.join(baseTypesDir, "ObjectType.ts"), await formatTs(`import { OntologyObject } from "./OntologyObject${importExt}";` + 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>")));
|
|
822
|
+
}
|
|
823
|
+
async function generateClientDir(runtimeDistDir, fs2, importExt = "") {
|
|
824
|
+
const pagingDir = path16__default.join(runtimeDistDir, "client");
|
|
825
|
+
await fs2.mkdir(pagingDir, {
|
|
826
|
+
recursive: true
|
|
827
|
+
});
|
|
828
|
+
await fs2.writeFile(path16__default.join(pagingDir, "index.ts"), await formatTs(`export * from "./clientOptions${importExt}";`));
|
|
829
|
+
await fs2.writeFile(path16__default.join(pagingDir, "clientOptions.ts"), await formatTs(`import {Auth} from "@osdk/legacy-client";` + reexportTypes(["FoundryClientOptions"], "<TAuth extends Auth = Auth>")));
|
|
830
|
+
}
|
|
831
|
+
async function generateFiltersDir(runtimeDistDir, fs2, importExt = "") {
|
|
832
|
+
const pagingDir = path16__default.join(runtimeDistDir, "filters");
|
|
833
|
+
await fs2.mkdir(pagingDir, {
|
|
834
|
+
recursive: true
|
|
835
|
+
});
|
|
836
|
+
await fs2.writeFile(path16__default.join(pagingDir, "index.ts"), await formatTs(`export * from "./ArrayFilter${importExt}";
|
|
837
|
+
export * from "./AttachmentFilter${importExt}";
|
|
838
|
+
export * from "./BooleanFilter${importExt}";
|
|
839
|
+
export * from "./DateTimeFilters${importExt}";
|
|
840
|
+
export * from "./Filters${importExt}";
|
|
841
|
+
export * from "./GeoPointFilter${importExt}";
|
|
842
|
+
export * from "./GeoShapeFilter${importExt}";
|
|
843
|
+
export * from "./NumericFilter${importExt}";
|
|
844
|
+
export * from "./Op${importExt}";
|
|
845
|
+
export * from "./OrderByOption${importExt}";
|
|
846
|
+
export * from "./StringFilter${importExt}";`));
|
|
847
|
+
await fs2.writeFile(path16__default.join(pagingDir, "ArrayFilter.ts"), await formatTs(`import { Attachment, GeoPoint, GeoShape, LocalDate, Timestamp } from "../baseTypes/index${importExt}";` + reexportConsts(["ArrayFilter"]) + reexportTypes(["ArrayFilter"], "<T extends string | number | Timestamp | LocalDate | boolean | GeoShape | GeoPoint | Attachment>")));
|
|
848
|
+
await fs2.writeFile(path16__default.join(pagingDir, "AttachmentFilter.ts"), await formatTs(reexportConsts(["AttachmentFilter"]) + reexportTypes(["AttachmentFilter"])));
|
|
849
|
+
await fs2.writeFile(path16__default.join(pagingDir, "BooleanFilter.ts"), await formatTs(reexportConsts(["BooleanFilter"]) + reexportTypes(["BooleanFilter"])));
|
|
850
|
+
await fs2.writeFile(path16__default.join(pagingDir, "GeoPointFilter.ts"), await formatTs(reexportConsts(["GeoPointFilter"]) + reexportTypes(["GeoPointFilter", "BoundingBox"])));
|
|
851
|
+
await fs2.writeFile(path16__default.join(pagingDir, "DateTimeFilters.ts"), await formatTs(reexportConsts(["TimestampFilter", "LocalDateFilter"]) + reexportTypes(["TimestampFilter", "LocalDateFilter"])));
|
|
852
|
+
await fs2.writeFile(path16__default.join(pagingDir, "GeoShapeFilter.ts"), await formatTs(reexportConsts(["GeoShapeFilter"]) + reexportTypes(["GeoShapeFilter"])));
|
|
853
|
+
await fs2.writeFile(path16__default.join(pagingDir, "NumericFilter.ts"), await formatTs(reexportConsts(["NumericFilter"]) + reexportTypes(["NumericFilter"])));
|
|
854
|
+
await fs2.writeFile(path16__default.join(pagingDir, "Op.ts"), await formatTs(reexportConsts(["Op"])));
|
|
855
|
+
await fs2.writeFile(path16__default.join(pagingDir, "OrderByOption.ts"), await formatTs(reexportConsts(["OrderByOption"]) + reexportTypes(["OrderByOption"])));
|
|
856
|
+
await fs2.writeFile(path16__default.join(pagingDir, "StringFilter.ts"), await formatTs(reexportConsts(["StringFilter"]) + reexportTypes(["StringFilter"])));
|
|
857
|
+
await fs2.writeFile(path16__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>")));
|
|
858
|
+
}
|
|
859
|
+
async function generateErrors(fs2, ontologyProviderDir) {
|
|
860
|
+
await fs2.writeFile(path16.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"])));
|
|
861
|
+
}
|
|
862
|
+
async function generateOntologyMetadata(fs2, ontologyProviderDir) {
|
|
863
|
+
await fs2.writeFile(path16.join(ontologyProviderDir, "OntologyMetadata.ts"), await formatTs(reexportTypes(["OntologyMetadata"])));
|
|
864
|
+
}
|
|
865
|
+
async function generateResult(fs2, ontologyProviderDir) {
|
|
866
|
+
await fs2.writeFile(path16.join(ontologyProviderDir, "Result.ts"), await formatTs(`import {FoundryApiError} from "@osdk/legacy-client";
|
|
867
|
+
` + 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>")));
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// src/v1.1/backcompat/internal-foundry-ontology-runtime-dist/generateOntologyProviderDir.ts
|
|
871
|
+
async function generateOntologyProviderDir(fs2, runtimeDistDir, importExt = "") {
|
|
872
|
+
const ontologyProviderDir = path16.join(runtimeDistDir, "ontologyProvider");
|
|
873
|
+
await fs2.mkdir(ontologyProviderDir, {
|
|
874
|
+
recursive: true
|
|
875
|
+
});
|
|
876
|
+
await generateErrors(fs2, ontologyProviderDir);
|
|
877
|
+
await generateOntologyMetadata(fs2, ontologyProviderDir);
|
|
878
|
+
await generateResult(fs2, ontologyProviderDir);
|
|
879
|
+
await fs2.writeFile(path16.join(ontologyProviderDir, "index.ts"), await formatTs(`
|
|
880
|
+
${""}
|
|
881
|
+
export * from "./Errors${importExt}";
|
|
882
|
+
export * from "./OntologyMetadata${importExt}";
|
|
883
|
+
${""}
|
|
884
|
+
${""}
|
|
885
|
+
// export * from "./Result${importExt}";
|
|
886
|
+
`));
|
|
887
|
+
}
|
|
888
|
+
async function generatePagingDir(runtimeDistDir, fs2, importExt = "") {
|
|
889
|
+
const pagingDir = path16.join(runtimeDistDir, "paging");
|
|
890
|
+
await fs2.mkdir(pagingDir, {
|
|
891
|
+
recursive: true
|
|
892
|
+
});
|
|
893
|
+
await fs2.writeFile(path16.join(pagingDir, "index.ts"), await formatTs(`export * from "./Page${importExt}";`));
|
|
894
|
+
await fs2.writeFile(path16.join(pagingDir, "Page.ts"), await formatTs(reexportTypes(["Page"], "<T>")));
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// src/v1.1/backcompat/generateOntologyRuntimeDistDir.ts
|
|
898
|
+
async function generateOntologyRuntimeDistDir(outDir, fs2, importExt = "") {
|
|
899
|
+
const runtimeDistDir = path16.join(outDir, "internal", "@foundry", "ontology-runtime", "dist");
|
|
900
|
+
await fs2.mkdir(runtimeDistDir, {
|
|
901
|
+
recursive: true
|
|
902
|
+
});
|
|
903
|
+
await generateOntologyProviderDir(fs2, runtimeDistDir, importExt);
|
|
904
|
+
await generateAggregationsDir(fs2, runtimeDistDir, importExt);
|
|
905
|
+
await generatePagingDir(runtimeDistDir, fs2, importExt);
|
|
906
|
+
await generateBaseTypesDir(runtimeDistDir, fs2, importExt);
|
|
907
|
+
await generateClientDir(runtimeDistDir, fs2, importExt);
|
|
908
|
+
await generateFiltersDir(runtimeDistDir, fs2, importExt);
|
|
909
|
+
await fs2.writeFile(
|
|
910
|
+
path16.join(runtimeDistDir, "index.ts"),
|
|
911
|
+
// TRASHFIXME
|
|
912
|
+
await formatTs(`
|
|
913
|
+
export * from "./aggregations/index${importExt}";
|
|
914
|
+
export * from "./baseTypes/index${importExt}";
|
|
915
|
+
${""}
|
|
916
|
+
// export * from "./filters/index${importExt}";
|
|
917
|
+
${""}
|
|
918
|
+
${""}
|
|
919
|
+
|
|
920
|
+
export * from "./ontologyProvider/index${importExt}";
|
|
921
|
+
export * from "./paging/index${importExt}";
|
|
922
|
+
`)
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
// src/v1.1/generateBackCompatDeprecatedExports.ts
|
|
927
|
+
async function generateBackCompatDeprecatedExports(fs2, outDir, importExt = "") {
|
|
928
|
+
await generateOntologyRuntimeDistDir(outDir, fs2, importExt);
|
|
929
|
+
await generateOAuthClientDistDir(outDir, fs2, importExt);
|
|
930
|
+
}
|
|
931
|
+
async function generateBatchActions(ontology, fs2, outDir, importExt = "") {
|
|
932
|
+
const importedObjects = /* @__PURE__ */ new Set();
|
|
933
|
+
let actionSignatures = [];
|
|
934
|
+
for (const action of Object.values(ontology.actionTypes)) {
|
|
935
|
+
const entries = Object.entries(action.parameters);
|
|
936
|
+
const modifiedEntityTypes = getModifiedEntityTypes(action);
|
|
937
|
+
const addedObjects = Array.from(modifiedEntityTypes.addedObjects);
|
|
938
|
+
const modifiedObjects = Array.from(modifiedEntityTypes.modifiedObjects);
|
|
939
|
+
addedObjects.forEach(importedObjects.add, importedObjects);
|
|
940
|
+
modifiedObjects.forEach(importedObjects.add, importedObjects);
|
|
941
|
+
let jsDocBlock = ["/**"];
|
|
942
|
+
if (action.description) {
|
|
943
|
+
jsDocBlock.push(`* ${action.description}`);
|
|
944
|
+
}
|
|
945
|
+
let parameterBlock = "";
|
|
946
|
+
if (entries.length > 0) {
|
|
947
|
+
parameterBlock = `params: {
|
|
948
|
+
`;
|
|
949
|
+
for (const [parameterName, parameterData] of entries) {
|
|
950
|
+
parameterBlock += `"${parameterName}"`;
|
|
951
|
+
parameterBlock += parameterData.required ? ": " : "?: ";
|
|
952
|
+
const typeScriptType = getTypeScriptTypeFromDataType(parameterData.dataType, importedObjects);
|
|
953
|
+
parameterBlock += `${typeScriptType};
|
|
954
|
+
`;
|
|
955
|
+
jsDocBlock.push(`* @param {${typeScriptType}} params.${parameterName}`);
|
|
956
|
+
}
|
|
957
|
+
parameterBlock += "}[], ";
|
|
958
|
+
} else {
|
|
959
|
+
parameterBlock = `params: Record<string,never>[], `;
|
|
960
|
+
}
|
|
961
|
+
jsDocBlock.push(`*/`);
|
|
962
|
+
actionSignatures.push(`
|
|
963
|
+
${jsDocBlock.join("\n")}
|
|
964
|
+
${action.apiName}<O extends BatchActionExecutionOptions>(${parameterBlock}options?: O):
|
|
965
|
+
Promise<Result<BatchActionResponseFromOptions<O, Edits<${addedObjects.length > 0 ? addedObjects.join(" | ") : "void"}, ${modifiedObjects.length > 0 ? modifiedObjects.join(" | ") : "void"}>>, ActionError>>;
|
|
966
|
+
`);
|
|
967
|
+
}
|
|
968
|
+
await fs2.mkdir(outDir, {
|
|
969
|
+
recursive: true
|
|
970
|
+
});
|
|
971
|
+
await fs2.writeFile(path16__default.join(outDir, "BatchActions.ts"), await formatTs(`
|
|
972
|
+
import type { ObjectSet, LocalDate, Timestamp, Attachment, Edits, ActionExecutionOptions, BatchActionExecutionOptions, ActionError, Result, ActionResponseFromOptions, BatchActionResponseFromOptions } from "@osdk/legacy-client";
|
|
973
|
+
${Array.from(importedObjects).map((importedObject) => `import type { ${importedObject} } from "../objects/${importedObject}${importExt}";`).join("\n")}
|
|
974
|
+
export interface BatchActions {
|
|
975
|
+
${actionSignatures.join("\n")}
|
|
976
|
+
}
|
|
977
|
+
`));
|
|
978
|
+
}
|
|
979
|
+
async function generateBulkActions(ontology, fs2, outDir, importExt = "") {
|
|
980
|
+
const importedObjects = /* @__PURE__ */ new Set();
|
|
981
|
+
let actionSignatures = [];
|
|
982
|
+
for (const action of Object.values(ontology.actionTypes)) {
|
|
983
|
+
const entries = Object.entries(action.parameters);
|
|
984
|
+
const modifiedEntityTypes = getModifiedEntityTypes(action);
|
|
985
|
+
const addedObjects = Array.from(modifiedEntityTypes.addedObjects);
|
|
986
|
+
const modifiedObjects = Array.from(modifiedEntityTypes.modifiedObjects);
|
|
987
|
+
addedObjects.forEach(importedObjects.add, importedObjects);
|
|
988
|
+
modifiedObjects.forEach(importedObjects.add, importedObjects);
|
|
989
|
+
let jsDocBlock = ["/**"];
|
|
990
|
+
if (action.description) {
|
|
991
|
+
jsDocBlock.push(`* ${action.description}`);
|
|
992
|
+
}
|
|
993
|
+
let parameterBlock = "";
|
|
994
|
+
if (entries.length > 0) {
|
|
995
|
+
parameterBlock = `params: {
|
|
996
|
+
`;
|
|
997
|
+
for (const [parameterName, parameterData] of entries) {
|
|
998
|
+
parameterBlock += `"${parameterName}"`;
|
|
999
|
+
parameterBlock += parameterData.required ? ": " : "?: ";
|
|
1000
|
+
const typeScriptType = getTypeScriptTypeFromDataType(parameterData.dataType, importedObjects);
|
|
1001
|
+
parameterBlock += `${typeScriptType};
|
|
1002
|
+
`;
|
|
1003
|
+
jsDocBlock.push(`* @param {${typeScriptType}} params.${parameterName}`);
|
|
1004
|
+
}
|
|
1005
|
+
parameterBlock += "}[], ";
|
|
1006
|
+
} else {
|
|
1007
|
+
parameterBlock = `params: Record<string,never>[], `;
|
|
1008
|
+
}
|
|
1009
|
+
jsDocBlock.push(`*/`);
|
|
1010
|
+
actionSignatures.push(`
|
|
1011
|
+
${jsDocBlock.join("\n")}
|
|
1012
|
+
${action.apiName}<O extends BulkActionExecutionOptions>(${parameterBlock}options?: O):
|
|
1013
|
+
Promise<Result<BulkActionResponseFromOptions<O, Edits<${addedObjects.length > 0 ? addedObjects.join(" | ") : "void"}, ${modifiedObjects.length > 0 ? modifiedObjects.join(" | ") : "void"}>>, ActionError>>;
|
|
1014
|
+
`);
|
|
1015
|
+
}
|
|
1016
|
+
await fs2.mkdir(outDir, {
|
|
1017
|
+
recursive: true
|
|
1018
|
+
});
|
|
1019
|
+
await fs2.writeFile(path16__default.join(outDir, "BulkActions.ts"), await formatTs(`
|
|
1020
|
+
import type { ObjectSet, LocalDate, Timestamp, Attachment, Edits, ActionExecutionOptions, BulkActionExecutionOptions, ActionError, Result, ActionResponseFromOptions, BulkActionResponseFromOptions } from "@osdk/legacy-client";
|
|
1021
|
+
${Array.from(importedObjects).map((importedObject) => `import type { ${importedObject} } from "../objects/${importedObject}${importExt}";`).join("\n")}
|
|
1022
|
+
export interface BulkActions {
|
|
1023
|
+
${actionSignatures.join("\n")}
|
|
1024
|
+
}
|
|
1025
|
+
`));
|
|
1026
|
+
}
|
|
1027
|
+
async function generateFoundryClientFile(fs2, outDir, importExt = "") {
|
|
1028
|
+
await fs2.writeFile(path16__default.join(outDir, "FoundryClient.ts"), await formatTs(`
|
|
1029
|
+
import { BaseFoundryClient } from "@osdk/legacy-client";
|
|
1030
|
+
import type { Auth, FoundryClientOptions } from "@osdk/legacy-client";
|
|
1031
|
+
import { Ontology } from "./Ontology${importExt}";
|
|
1032
|
+
|
|
1033
|
+
export class FoundryClient<TAuth extends Auth = Auth> extends BaseFoundryClient<typeof Ontology, TAuth> {
|
|
1034
|
+
constructor(options: FoundryClientOptions<TAuth>) {
|
|
1035
|
+
super(options, Ontology);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
get ontology(): Ontology {
|
|
1039
|
+
return super.ontology;
|
|
1040
|
+
}
|
|
1041
|
+
}`));
|
|
1042
|
+
}
|
|
1043
|
+
async function generateIndexFile(fs2, outDir, importExt) {
|
|
1044
|
+
await fs2.mkdir(outDir, {
|
|
1045
|
+
recursive: true
|
|
1046
|
+
});
|
|
1047
|
+
await fs2.writeFile(path16.join(outDir, "index.ts"), await formatTs(`
|
|
1048
|
+
export * from "@osdk/legacy-client";
|
|
1049
|
+
export type { Ontology } from "./Ontology${importExt}";
|
|
1050
|
+
export { FoundryClient } from "./FoundryClient${importExt}";
|
|
1051
|
+
`));
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
// src/util/commaSeparatedIdentifiers.ts
|
|
1055
|
+
function commaSeparatedIdentifiers(identifiers, alternateNames) {
|
|
1056
|
+
return identifiers.map((i) => {
|
|
1057
|
+
const alt = alternateNames?.get(i);
|
|
1058
|
+
if (alt) {
|
|
1059
|
+
return `${i}: ${alt}`;
|
|
1060
|
+
}
|
|
1061
|
+
return i;
|
|
1062
|
+
}).join(",");
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
// src/util/commaSeparatedTypeIdentifiers.ts
|
|
1066
|
+
function commaSeparatedTypeIdentifiers(identifiers, altNames) {
|
|
1067
|
+
return identifiers.map((i) => `${i}: typeof ${altNames?.get(i) ?? i}`).join(",");
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
// src/v1.1/generateMetadataFile.ts
|
|
1071
|
+
async function generateMetadataFile(ontology, userAgent, fs2, outDir, importExt = "") {
|
|
1072
|
+
const objectNames = Object.keys(ontology.objectTypes);
|
|
1073
|
+
const actionNames = Object.keys(ontology.actionTypes);
|
|
1074
|
+
const queryNames = Object.keys(ontology.queryTypes);
|
|
1075
|
+
const actionAltNames = /* @__PURE__ */ new Map();
|
|
1076
|
+
const queryAltNames = /* @__PURE__ */ new Map();
|
|
1077
|
+
const seenIdentifiers = new Set(objectNames);
|
|
1078
|
+
for (const actionName of actionNames) {
|
|
1079
|
+
if (seenIdentifiers.has(actionName)) {
|
|
1080
|
+
actionAltNames.set(actionName, `${actionName}Action`);
|
|
1081
|
+
} else {
|
|
1082
|
+
seenIdentifiers.add(actionName);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
for (const queryName of queryNames) {
|
|
1086
|
+
if (seenIdentifiers.has(queryName)) {
|
|
1087
|
+
queryAltNames.set(queryName, `${queryName}Query`);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
const getImportClause = (name, altNames) => {
|
|
1091
|
+
const alt = altNames.get(name);
|
|
1092
|
+
if (alt) {
|
|
1093
|
+
return `${name} as ${alt}`;
|
|
1094
|
+
} else {
|
|
1095
|
+
return name;
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
await fs2.writeFile(path16__default.join(outDir, "Ontology.ts"), await formatTs(`
|
|
1099
|
+
import type { OntologyDefinition } from "@osdk/api";
|
|
1100
|
+
import type { Ontology as ClientOntology } from "@osdk/legacy-client";
|
|
1101
|
+
import type { Objects } from "./ontology/objects/Objects${importExt}";
|
|
1102
|
+
import type { Actions } from "./ontology/actions/Actions${importExt}";
|
|
1103
|
+
import type { Queries } from "./ontology/queries/Queries${importExt}";
|
|
1104
|
+
import type { BatchActions } from "./ontology/actions/BatchActions${importExt}";
|
|
1105
|
+
import type { BulkActions } from "./ontology/actions/BulkActions${importExt}";
|
|
1106
|
+
${objectNames.map((name) => `import {${name}} from "./ontology/objects/${name}${importExt}";`).join("\n")}
|
|
1107
|
+
${actionNames.map((name) => `import {${getImportClause(name, actionAltNames)}} from "./ontology/actions/${name}${importExt}";`).join("\n")}
|
|
1108
|
+
${queryNames.map((name) => `import {${getImportClause(name, queryAltNames)}} from "./ontology/queries/${name}${importExt}";`).join("\n")}
|
|
1109
|
+
|
|
1110
|
+
export const Ontology : {
|
|
1111
|
+
metadata: {
|
|
1112
|
+
ontologyRid: "${ontology.ontology.rid}",
|
|
1113
|
+
ontologyApiName: "${ontology.ontology.apiName}",
|
|
1114
|
+
userAgent: "${userAgent}",
|
|
1115
|
+
},
|
|
1116
|
+
objects: {
|
|
1117
|
+
${commaSeparatedTypeIdentifiers(objectNames)}
|
|
1118
|
+
},
|
|
1119
|
+
actions: {
|
|
1120
|
+
${commaSeparatedTypeIdentifiers(actionNames, actionAltNames)}
|
|
1121
|
+
},
|
|
1122
|
+
queries: {
|
|
1123
|
+
${commaSeparatedTypeIdentifiers(queryNames, queryAltNames)}
|
|
1124
|
+
},
|
|
1125
|
+
} = {
|
|
1126
|
+
metadata: {
|
|
1127
|
+
ontologyRid: "${ontology.ontology.rid}" as const,
|
|
1128
|
+
ontologyApiName: "${ontology.ontology.apiName}" as const,
|
|
1129
|
+
userAgent: "${userAgent}" as const,
|
|
1130
|
+
},
|
|
1131
|
+
objects: {
|
|
1132
|
+
${commaSeparatedIdentifiers(objectNames)}
|
|
1133
|
+
},
|
|
1134
|
+
actions: {
|
|
1135
|
+
${commaSeparatedIdentifiers(actionNames, actionAltNames)}
|
|
1136
|
+
},
|
|
1137
|
+
queries: {
|
|
1138
|
+
${commaSeparatedIdentifiers(queryNames, queryAltNames)}
|
|
1139
|
+
}
|
|
1140
|
+
} satisfies OntologyDefinition<
|
|
1141
|
+
${stringUnionFrom(objectNames)},
|
|
1142
|
+
${stringUnionFrom(Object.values(ontology.actionTypes).map((actionType) => actionType.apiName))},
|
|
1143
|
+
${stringUnionFrom(Object.values(ontology.queryTypes).map((queryType) => queryType.apiName))}>;
|
|
1144
|
+
|
|
1145
|
+
export interface Ontology extends ClientOntology<typeof Ontology> {
|
|
1146
|
+
objects: Objects;
|
|
1147
|
+
actions: Actions;
|
|
1148
|
+
/** @deprecated use batchActions */
|
|
1149
|
+
bulkActions: BulkActions;
|
|
1150
|
+
batchActions: BatchActions;
|
|
1151
|
+
queries: Queries;
|
|
1152
|
+
}`));
|
|
1153
|
+
}
|
|
1154
|
+
function stringUnionFrom(values) {
|
|
1155
|
+
if (values.length === 0) {
|
|
1156
|
+
return "never";
|
|
1157
|
+
}
|
|
1158
|
+
return values.map((n) => `"${n}"`).join("|");
|
|
1159
|
+
}
|
|
1160
|
+
async function generateObjectsInterfaceFile(ontology, fs2, outDir, importExt = "") {
|
|
1161
|
+
await fs2.mkdir(outDir, {
|
|
1162
|
+
recursive: true
|
|
1163
|
+
});
|
|
1164
|
+
await fs2.writeFile(path16__default.join(outDir, "Objects.ts"), await formatTs(`
|
|
1165
|
+
import { BaseObjectSet } from "@osdk/legacy-client";
|
|
1166
|
+
${Array.from(Object.keys(ontology.objectTypes)).map((importedObject) => `import type { ${importedObject} } from "./${importedObject}${importExt}";`).join("\n")}
|
|
1167
|
+
|
|
1168
|
+
export interface Objects {
|
|
1169
|
+
${Object.keys(ontology.objectTypes).map((apiName) => `${apiName} : BaseObjectSet<${apiName}>;`).join("\n")}
|
|
1170
|
+
}
|
|
1171
|
+
;`));
|
|
1172
|
+
}
|
|
1173
|
+
async function generateObjectsInterfaceSupportFiles(ontology, fs2, outDir, importExt = "") {
|
|
1174
|
+
await fs2.mkdir(outDir, {
|
|
1175
|
+
recursive: true
|
|
1176
|
+
});
|
|
1177
|
+
for (const {
|
|
1178
|
+
objectType: {
|
|
1179
|
+
apiName
|
|
1180
|
+
}
|
|
1181
|
+
} of Object.values(ontology.objectTypes)) {
|
|
1182
|
+
const fileName = join(outDir, `${apiName}.ts`);
|
|
1183
|
+
const localApiName = `OG_${apiName}`;
|
|
1184
|
+
const contents = [];
|
|
1185
|
+
contents.push(`import { ObjectSetAggregateArg, ObjectSetFilterArg, ObjectSetGroupByArg, ObjectSetMultipleAggregateArg, ObjectSetOrderByArg } from "@osdk/legacy-client";`);
|
|
1186
|
+
contents.push(`import { ${apiName} as ${localApiName} } from "../${apiName}${importExt}";`);
|
|
1187
|
+
contents.push("");
|
|
1188
|
+
contents.push(`/** @deprecated Use ${apiName} from ontology/objects instead */`, `export type ${apiName} = ${localApiName};`);
|
|
1189
|
+
contents.push(`/** @deprecated Use ObjectSetFilterArg<${apiName}> instead */`, `export type ${apiName}Filter = ObjectSetFilterArg<${localApiName}>;`);
|
|
1190
|
+
contents.push(`/** @deprecated Use ObjectSetOrderByArg<${apiName}> instead */`, `export type ${apiName}OrderBy = ObjectSetOrderByArg<${localApiName}>;`);
|
|
1191
|
+
contents.push(`/** @deprecated Use ObjectSetGroupByArg<${apiName}> instead */`, `export type ${apiName}GroupByProperties = ObjectSetGroupByArg<${localApiName}>;`);
|
|
1192
|
+
contents.push(`
|
|
1193
|
+
/**
|
|
1194
|
+
* Aggregation properties for ${apiName}
|
|
1195
|
+
* @deprecated Use ObjectSetAggregateArg<${apiName}> instead
|
|
1196
|
+
*/`, `export type ${apiName}AggregationProperties = ObjectSetAggregateArg<${localApiName}>;`);
|
|
1197
|
+
contents.push(`
|
|
1198
|
+
/**
|
|
1199
|
+
* Multiple aggregation properties for ${apiName}.
|
|
1200
|
+
* @deprecated Use ObjectSetMultipleAggregateArg<${apiName}> instead
|
|
1201
|
+
*/`, `export type ${apiName}MultipleAggregationProperties = ObjectSetMultipleAggregateArg<${localApiName}>;`);
|
|
1202
|
+
await fs2.writeFile(fileName, contents.join("\n"));
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
async function generateOntologyIndexFile(fs2, outDir) {
|
|
1206
|
+
await fs2.mkdir(outDir, {
|
|
1207
|
+
recursive: true
|
|
1208
|
+
});
|
|
1209
|
+
await fs2.writeFile(path16.join(outDir, "index.ts"), await formatTs(`
|
|
1210
|
+
export type { ObjectSet } from "@osdk/legacy-client";
|
|
1211
|
+
`));
|
|
1212
|
+
}
|
|
1213
|
+
async function generatePerObjectInterfaceAndDataFiles(ontology, fs2, outDir, importExt = "") {
|
|
1214
|
+
await fs2.mkdir(outDir, {
|
|
1215
|
+
recursive: true
|
|
1216
|
+
});
|
|
1217
|
+
await Promise.all(Object.values(ontology.objectTypes).map(async (object) => {
|
|
1218
|
+
object.linkTypes;
|
|
1219
|
+
await fs2.writeFile(path16__default.join(outDir, `${object.objectType.apiName}.ts`), await formatTs(`
|
|
1220
|
+
import type { ObjectTypeDefinition, ObjectTypeLinkDefinition, PropertyDef } from "@osdk/api";
|
|
1221
|
+
${wireObjectTypeV2ToObjectInterfaceStringV1(object, importExt)}
|
|
1222
|
+
|
|
1223
|
+
${wireObjectTypeV2ToSdkObjectConst(object, importExt)}
|
|
1224
|
+
`));
|
|
1225
|
+
}));
|
|
1226
|
+
await fs2.writeFile(path16__default.join(outDir, "index.ts"), await formatTs(`
|
|
1227
|
+
${Object.keys(ontology.objectTypes).map((apiName) => `export * from "./${apiName}${importExt}";`).join("\n")}
|
|
1228
|
+
export type { ObjectSet } from "@osdk/legacy-client";
|
|
1229
|
+
|
|
1230
|
+
`));
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
// src/shared/isNullableQueryDataType.ts
|
|
1234
|
+
function isNullableQueryDataType(input) {
|
|
1235
|
+
if (input.type === "null") {
|
|
1236
|
+
return true;
|
|
1237
|
+
}
|
|
1238
|
+
if (input.type === "union") {
|
|
1239
|
+
return input.unionTypes.some((t) => isNullableQueryDataType(t));
|
|
1240
|
+
}
|
|
1241
|
+
return false;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
// src/shared/wireQueryDataTypeToQueryDataTypeDefinition.ts
|
|
1245
|
+
function wireQueryDataTypeToQueryDataTypeDefinition(input) {
|
|
1246
|
+
switch (input.type) {
|
|
1247
|
+
case "double":
|
|
1248
|
+
case "float":
|
|
1249
|
+
case "integer":
|
|
1250
|
+
case "long":
|
|
1251
|
+
case "attachment":
|
|
1252
|
+
case "boolean":
|
|
1253
|
+
case "date":
|
|
1254
|
+
case "string":
|
|
1255
|
+
case "timestamp":
|
|
1256
|
+
return {
|
|
1257
|
+
type: input.type,
|
|
1258
|
+
nullable: false
|
|
1259
|
+
};
|
|
1260
|
+
case "object":
|
|
1261
|
+
return {
|
|
1262
|
+
type: "object",
|
|
1263
|
+
object: input.objectTypeApiName,
|
|
1264
|
+
nullable: false
|
|
1265
|
+
};
|
|
1266
|
+
case "objectSet":
|
|
1267
|
+
return {
|
|
1268
|
+
type: "objectSet",
|
|
1269
|
+
objectSet: input.objectTypeApiName,
|
|
1270
|
+
nullable: false
|
|
1271
|
+
};
|
|
1272
|
+
case "array":
|
|
1273
|
+
return {
|
|
1274
|
+
...wireQueryDataTypeToQueryDataTypeDefinition(input.subType),
|
|
1275
|
+
multiplicity: true
|
|
1276
|
+
};
|
|
1277
|
+
case "set":
|
|
1278
|
+
return {
|
|
1279
|
+
type: "set",
|
|
1280
|
+
set: wireQueryDataTypeToQueryDataTypeDefinition(input.subType),
|
|
1281
|
+
nullable: false
|
|
1282
|
+
};
|
|
1283
|
+
case "union":
|
|
1284
|
+
const allowNulls = isNullableQueryDataType(input);
|
|
1285
|
+
if (allowNulls && input.unionTypes.length === 2) {
|
|
1286
|
+
const nonnull = input.unionTypes.find((t) => t.type != null);
|
|
1287
|
+
if (nonnull) {
|
|
1288
|
+
return {
|
|
1289
|
+
...wireQueryDataTypeToQueryDataTypeDefinition(nonnull),
|
|
1290
|
+
nullable: true
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
return {
|
|
1295
|
+
type: "union",
|
|
1296
|
+
union: input.unionTypes.reduce((acc, t) => {
|
|
1297
|
+
if (t.type === "null") {
|
|
1298
|
+
return acc;
|
|
1299
|
+
}
|
|
1300
|
+
acc.push(wireQueryDataTypeToQueryDataTypeDefinition(t));
|
|
1301
|
+
return acc;
|
|
1302
|
+
}, []),
|
|
1303
|
+
nullable: allowNulls
|
|
1304
|
+
};
|
|
1305
|
+
case "struct":
|
|
1306
|
+
return {
|
|
1307
|
+
type: "struct",
|
|
1308
|
+
struct: Object.fromEntries(input.fields.map((f) => [f.name, wireQueryDataTypeToQueryDataTypeDefinition(f.fieldType)])),
|
|
1309
|
+
nullable: false
|
|
1310
|
+
};
|
|
1311
|
+
case "twoDimensionalAggregation":
|
|
1312
|
+
return {
|
|
1313
|
+
type: "twoDimensionalAggregation",
|
|
1314
|
+
twoDimensionalAggregation: get2DQueryAggregationProps(input)
|
|
1315
|
+
};
|
|
1316
|
+
case "threeDimensionalAggregation":
|
|
1317
|
+
return {
|
|
1318
|
+
type: "threeDimensionalAggregation",
|
|
1319
|
+
threeDimensionalAggregation: get3DQueryAggregationProps(input)
|
|
1320
|
+
};
|
|
1321
|
+
case "null":
|
|
1322
|
+
case "unsupported":
|
|
1323
|
+
throw new Error(`Accidentally tried to handle QueryDataType.type ${input.type}`);
|
|
1324
|
+
default:
|
|
1325
|
+
throw new Error(`Unsupported QueryDataType.type ${input.type}`);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
function get2DQueryAggregationProps(input) {
|
|
1329
|
+
if (input.keyType.type === "range") {
|
|
1330
|
+
return {
|
|
1331
|
+
keyType: input.keyType.type,
|
|
1332
|
+
keySubtype: input.keyType.subType.type,
|
|
1333
|
+
valueType: input.valueType.type
|
|
1334
|
+
};
|
|
1335
|
+
} else {
|
|
1336
|
+
if (guardInvalidKeyTypes(input.keyType)) {
|
|
1337
|
+
return {
|
|
1338
|
+
keyType: input.keyType.type,
|
|
1339
|
+
valueType: input.valueType.type
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
throw new Error(`Cannot create 2D aggregation with ${input.keyType.type} as its type`);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
function get3DQueryAggregationProps(input) {
|
|
1346
|
+
if (input.keyType.type === "range") {
|
|
1347
|
+
return {
|
|
1348
|
+
keyType: input.keyType.type,
|
|
1349
|
+
keySubtype: input.keyType.subType.type,
|
|
1350
|
+
valueType: get2DQueryAggregationProps(input.valueType)
|
|
1351
|
+
};
|
|
1352
|
+
} else {
|
|
1353
|
+
if (guardInvalidKeyTypes(input.keyType)) {
|
|
1354
|
+
return {
|
|
1355
|
+
keyType: input.keyType.type,
|
|
1356
|
+
valueType: get2DQueryAggregationProps(input.valueType)
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
throw new Error(`Cannot create 3D aggregation with ${input.keyType.type} as its type`);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
function guardInvalidKeyTypes(key) {
|
|
1363
|
+
return key.type === "string" || key.type === "boolean";
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
// src/shared/wireQueryTypeV2ToSdkQueryDefinition.ts
|
|
1367
|
+
function wireQueryTypeV2ToSdkQueryDefinition(input) {
|
|
1368
|
+
return {
|
|
1369
|
+
type: "query",
|
|
1370
|
+
apiName: input.apiName,
|
|
1371
|
+
description: input.description,
|
|
1372
|
+
displayName: input.displayName,
|
|
1373
|
+
version: input.version,
|
|
1374
|
+
parameters: Object.fromEntries(Object.entries(input.parameters).map(([name, parameter]) => [name, wireQueryParameterV2ToQueryParameterDefinition(parameter)])),
|
|
1375
|
+
output: wireQueryDataTypeToQueryDataTypeDefinition(input.output)
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
function wireQueryParameterV2ToQueryParameterDefinition(parameter) {
|
|
1379
|
+
return {
|
|
1380
|
+
description: parameter.description,
|
|
1381
|
+
...wireQueryDataTypeToQueryDataTypeDefinition(parameter.dataType)
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
// src/v1.1/generatePerQueryDataFiles.ts
|
|
1386
|
+
async function generatePerQueryDataFiles(ontology, fs2, outDir, importExt = "") {
|
|
1387
|
+
await fs2.mkdir(outDir, {
|
|
1388
|
+
recursive: true
|
|
1389
|
+
});
|
|
1390
|
+
await Promise.all(Object.values(ontology.queryTypes).map(async (query) => {
|
|
1391
|
+
const objectTypes = getObjectTypesFromQuery(query);
|
|
1392
|
+
await fs2.writeFile(path16__default.join(outDir, `${query.apiName}.ts`), await formatTs(`
|
|
1393
|
+
import { QueryDefinition } from "@osdk/api";
|
|
1394
|
+
|
|
1395
|
+
export const ${query.apiName} = ${JSON.stringify(wireQueryTypeV2ToSdkQueryDefinition(query))} satisfies QueryDefinition<"${query.apiName}", ${objectTypes.length > 0 ? objectTypes.map((apiName) => `"${apiName}"`).join("|") : "never"}>;`));
|
|
1396
|
+
}));
|
|
1397
|
+
await fs2.writeFile(path16__default.join(outDir, "index.ts"), await formatTs(`
|
|
1398
|
+
${Object.values(ontology.queryTypes).map((query) => `export * from "./${query.apiName}${importExt}";`).join("\n")}
|
|
1399
|
+
`));
|
|
1400
|
+
}
|
|
1401
|
+
function getObjectTypesFromQuery(query) {
|
|
1402
|
+
const types = /* @__PURE__ */ new Set();
|
|
1403
|
+
for (const {
|
|
1404
|
+
dataType
|
|
1405
|
+
} of Object.values(query.parameters)) {
|
|
1406
|
+
getObjectTypesFromDataType(dataType, types);
|
|
1407
|
+
}
|
|
1408
|
+
getObjectTypesFromDataType(query.output, types);
|
|
1409
|
+
return Array.from(types);
|
|
1410
|
+
}
|
|
1411
|
+
function getObjectTypesFromDataType(dataType, types) {
|
|
1412
|
+
switch (dataType.type) {
|
|
1413
|
+
case "array":
|
|
1414
|
+
case "set":
|
|
1415
|
+
getObjectTypesFromDataType(dataType.subType, types);
|
|
1416
|
+
return;
|
|
1417
|
+
case "object":
|
|
1418
|
+
types.add(dataType.objectTypeApiName);
|
|
1419
|
+
return;
|
|
1420
|
+
case "objectSet":
|
|
1421
|
+
types.add(dataType.objectTypeApiName);
|
|
1422
|
+
return;
|
|
1423
|
+
case "struct":
|
|
1424
|
+
for (const prop of Object.values(dataType.fields)) {
|
|
1425
|
+
getObjectTypesFromDataType(prop.fieldType, types);
|
|
1426
|
+
}
|
|
1427
|
+
return;
|
|
1428
|
+
case "union":
|
|
1429
|
+
for (const type of dataType.unionTypes) {
|
|
1430
|
+
getObjectTypesFromDataType(type, types);
|
|
1431
|
+
}
|
|
1432
|
+
return;
|
|
1433
|
+
case "attachment":
|
|
1434
|
+
case "boolean":
|
|
1435
|
+
case "date":
|
|
1436
|
+
case "double":
|
|
1437
|
+
case "float":
|
|
1438
|
+
case "integer":
|
|
1439
|
+
case "long":
|
|
1440
|
+
case "null":
|
|
1441
|
+
case "string":
|
|
1442
|
+
case "threeDimensionalAggregation":
|
|
1443
|
+
case "timestamp":
|
|
1444
|
+
case "twoDimensionalAggregation":
|
|
1445
|
+
case "unsupported":
|
|
1446
|
+
return;
|
|
1447
|
+
default:
|
|
1448
|
+
throw new Error(`Cannot find object types from unsupported QueryDataType ${dataType.type}`);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
async function generateQueries(ontology, fs2, outDir, importExt = "") {
|
|
1452
|
+
const importedObjects = /* @__PURE__ */ new Set();
|
|
1453
|
+
const signatures = [];
|
|
1454
|
+
for (const query of Object.values(ontology.queryTypes)) {
|
|
1455
|
+
const jsDocBlock = ["/**"];
|
|
1456
|
+
if (query.description) {
|
|
1457
|
+
jsDocBlock.push(`* ${query.description}`);
|
|
1458
|
+
}
|
|
1459
|
+
const outputType = handleQueryDataType(query.output, importedObjects, true);
|
|
1460
|
+
const paramEntries = [];
|
|
1461
|
+
for (const [name, parameter] of Object.entries(query.parameters)) {
|
|
1462
|
+
const nullable = isNullableQueryDataType(parameter.dataType);
|
|
1463
|
+
const type = handleQueryDataType(parameter.dataType, importedObjects, false);
|
|
1464
|
+
paramEntries.push(`"${name}"${nullable ? "?" : ""}: ${type}`);
|
|
1465
|
+
jsDocBlock.push(`* @param {${sanitizeDocTypeName(type)}} params.${name}${parameter.description ? ` - ${parameter.description}` : ""}`);
|
|
1466
|
+
}
|
|
1467
|
+
const param = paramEntries.length === 0 ? "" : `params: { ${paramEntries.join("; ")} }`;
|
|
1468
|
+
jsDocBlock.push(`* @returns ${sanitizeDocTypeName(outputType)}`, "*/");
|
|
1469
|
+
signatures.push(`
|
|
1470
|
+
${jsDocBlock.join("\n")}
|
|
1471
|
+
${query.apiName}(${param}): Promise<Result<QueryResponse<${outputType}>, QueryError>>;
|
|
1472
|
+
`);
|
|
1473
|
+
}
|
|
1474
|
+
await fs2.mkdir(outDir, {
|
|
1475
|
+
recursive: true
|
|
1476
|
+
});
|
|
1477
|
+
await fs2.writeFile(path16__default.join(outDir, "Queries.ts"), await formatTs(`
|
|
1478
|
+
import type { QueryResponse, QueryError, Result, Timestamp, LocalDate, Range, Attachment, ObjectSet, TwoDimensionalAggregation, ThreeDimensionalAggregation } from "@osdk/legacy-client";
|
|
1479
|
+
${Array.from(importedObjects).map((importedObject) => `import type { ${importedObject} } from "../objects/${importedObject}${importExt}";`).join("\n")}
|
|
1480
|
+
|
|
1481
|
+
export interface Queries {
|
|
1482
|
+
${signatures.join("\n")}
|
|
1483
|
+
}
|
|
1484
|
+
`));
|
|
1485
|
+
}
|
|
1486
|
+
function handleQueryDataType(dataType, importedObjects, isReturnValue) {
|
|
1487
|
+
switch (dataType.type) {
|
|
1488
|
+
case "boolean":
|
|
1489
|
+
return "boolean";
|
|
1490
|
+
case "string":
|
|
1491
|
+
return "string";
|
|
1492
|
+
case "double":
|
|
1493
|
+
case "float":
|
|
1494
|
+
case "integer":
|
|
1495
|
+
return "number";
|
|
1496
|
+
case "long":
|
|
1497
|
+
return isReturnValue ? "string" : "string | number";
|
|
1498
|
+
case "date":
|
|
1499
|
+
return "LocalDate";
|
|
1500
|
+
case "timestamp":
|
|
1501
|
+
return "Timestamp";
|
|
1502
|
+
case "attachment":
|
|
1503
|
+
return "Attachment";
|
|
1504
|
+
case "array":
|
|
1505
|
+
return `Array<${handleQueryDataType(dataType.subType, importedObjects, isReturnValue)}>`;
|
|
1506
|
+
case "object": {
|
|
1507
|
+
const objectType = dataType.objectTypeApiName;
|
|
1508
|
+
importedObjects.add(objectType);
|
|
1509
|
+
return isReturnValue ? objectType : `${objectType} | ${objectType}["__primaryKey"]`;
|
|
1510
|
+
}
|
|
1511
|
+
case "objectSet": {
|
|
1512
|
+
const objectType = dataType.objectTypeApiName;
|
|
1513
|
+
importedObjects.add(objectType);
|
|
1514
|
+
return `ObjectSet<${objectType}>`;
|
|
1515
|
+
}
|
|
1516
|
+
case "set":
|
|
1517
|
+
return `Set<${handleQueryDataType(dataType.subType, importedObjects, isReturnValue)}>`;
|
|
1518
|
+
case "struct":
|
|
1519
|
+
const properties = dataType.fields.map((field) => {
|
|
1520
|
+
const isNullable = isNullableQueryDataType(field.fieldType);
|
|
1521
|
+
return `${field.name}${isNullable ? "?" : ""}: ${handleQueryDataType(field.fieldType, importedObjects, isReturnValue)}`;
|
|
1522
|
+
});
|
|
1523
|
+
return `{ ${properties.join(",\n")} }`;
|
|
1524
|
+
case "union":
|
|
1525
|
+
return dataType.unionTypes.map((type) => handleQueryDataType(type, importedObjects, isReturnValue)).filter((type) => type !== "null").join("|");
|
|
1526
|
+
case "twoDimensionalAggregation":
|
|
1527
|
+
dataType.valueType;
|
|
1528
|
+
return `TwoDimensionalAggregation<
|
|
1529
|
+
${aggregationKeyToTypescriptType(dataType.keyType)},
|
|
1530
|
+
${aggregationValueToTypescriptType(dataType.valueType)}
|
|
1531
|
+
>`;
|
|
1532
|
+
case "threeDimensionalAggregation":
|
|
1533
|
+
return `ThreeDimensionalAggregation<
|
|
1534
|
+
${aggregationKeyToTypescriptType(dataType.keyType)},
|
|
1535
|
+
${aggregationKeyToTypescriptType(dataType.valueType.keyType)},
|
|
1536
|
+
${aggregationValueToTypescriptType(dataType.valueType.valueType)}
|
|
1537
|
+
>`;
|
|
1538
|
+
case "null":
|
|
1539
|
+
return "null";
|
|
1540
|
+
case "unsupported":
|
|
1541
|
+
throw new Error("Cannot generate queries for unsupported type");
|
|
1542
|
+
default:
|
|
1543
|
+
throw new Error(`Cannot generate queries for type ${dataType.type}`);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
function aggregationKeyToTypescriptType(keyType) {
|
|
1547
|
+
switch (keyType.type) {
|
|
1548
|
+
case "boolean":
|
|
1549
|
+
return "boolean";
|
|
1550
|
+
case "double":
|
|
1551
|
+
case "integer":
|
|
1552
|
+
return "number";
|
|
1553
|
+
case "string":
|
|
1554
|
+
return "string";
|
|
1555
|
+
case "date":
|
|
1556
|
+
return "LocalDate";
|
|
1557
|
+
case "timestamp":
|
|
1558
|
+
return "Timestamp";
|
|
1559
|
+
case "range":
|
|
1560
|
+
return `Range<${aggregationRangeToTypescriptType(keyType.subType)}>`;
|
|
1561
|
+
default:
|
|
1562
|
+
throw new Error(`Unknown TwoDimensionalAggregation keyType ${keyType.type}`);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
function aggregationRangeToTypescriptType(subType) {
|
|
1566
|
+
switch (subType.type) {
|
|
1567
|
+
case "date":
|
|
1568
|
+
return "LocalDate";
|
|
1569
|
+
case "double":
|
|
1570
|
+
case "integer":
|
|
1571
|
+
return "number";
|
|
1572
|
+
case "timestamp":
|
|
1573
|
+
return "Timestamp";
|
|
1574
|
+
default:
|
|
1575
|
+
throw new Error(`Unsupported QueryAggregationRangeSubType ${subType.type}`);
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
function aggregationValueToTypescriptType(valueType) {
|
|
1579
|
+
switch (valueType.type) {
|
|
1580
|
+
case "date":
|
|
1581
|
+
return "LocalDate";
|
|
1582
|
+
case "double":
|
|
1583
|
+
return "number";
|
|
1584
|
+
case "timestamp":
|
|
1585
|
+
return "Timestamp";
|
|
1586
|
+
default:
|
|
1587
|
+
throw new Error(`Unsupported QueryAggregationValueType ${valueType.type}`);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
function sanitizeDocTypeName(type) {
|
|
1591
|
+
return type.replace(/\s/g, "");
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
// src/v1.1/generateClientSdkVersionOneDotOne.ts
|
|
1595
|
+
async function generateClientSdkVersionOneDotOne(ontology, userAgent, fs2, outDir, packageType = "commonjs") {
|
|
1596
|
+
const importExt = packageType === "module" ? ".js" : "";
|
|
1597
|
+
const objectsDir = path16.join(outDir, "ontology", "objects");
|
|
1598
|
+
const actionsDir = path16.join(outDir, "ontology", "actions");
|
|
1599
|
+
const queriesDir = path16.join(outDir, "ontology", "queries");
|
|
1600
|
+
await verifyOutdir(outDir, fs2);
|
|
1601
|
+
await fs2.mkdir(outDir, {
|
|
1602
|
+
recursive: true
|
|
1603
|
+
});
|
|
1604
|
+
const sanitizedOntology = sanitizeMetadata(ontology);
|
|
1605
|
+
await generateFoundryClientFile(fs2, outDir, importExt);
|
|
1606
|
+
await generateMetadataFile(sanitizedOntology, userAgent, fs2, outDir, importExt);
|
|
1607
|
+
await generateOntologyIndexFile(fs2, path16.join(outDir, "ontology"));
|
|
1608
|
+
await generateObjectsInterfaceFile(sanitizedOntology, fs2, objectsDir, importExt);
|
|
1609
|
+
await generateObjectsInterfaceSupportFiles(sanitizedOntology, fs2, path16.join(objectsDir, "objects-api"), importExt);
|
|
1610
|
+
await generatePerObjectInterfaceAndDataFiles(sanitizedOntology, fs2, objectsDir, importExt);
|
|
1611
|
+
await generateActions(sanitizedOntology, fs2, actionsDir, importExt);
|
|
1612
|
+
await generateBatchActions(sanitizedOntology, fs2, actionsDir, importExt);
|
|
1613
|
+
await generateBulkActions(sanitizedOntology, fs2, actionsDir, importExt);
|
|
1614
|
+
await generatePerActionDataFiles(sanitizedOntology, fs2, actionsDir, importExt, false);
|
|
1615
|
+
await generateQueries(sanitizedOntology, fs2, queriesDir, importExt);
|
|
1616
|
+
await generatePerQueryDataFiles(sanitizedOntology, fs2, queriesDir, importExt);
|
|
1617
|
+
await generateIndexFile(fs2, outDir, importExt);
|
|
1618
|
+
await generateBackCompatDeprecatedExports(fs2, outDir, importExt);
|
|
1619
|
+
}
|
|
1620
|
+
function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceDef, v2 = false) {
|
|
1621
|
+
const definition = deleteUndefineds(__UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(interfaceDef, v2));
|
|
1622
|
+
const objectDefIdentifier = getObjectDefIdentifier(interfaceDef.apiName, v2);
|
|
1623
|
+
function getV2Types() {
|
|
1624
|
+
return `
|
|
1625
|
+
export interface ${objectDefIdentifier} extends InterfaceDefinition<"${interfaceDef.apiName}", ${interfaceDef.apiName}>, VersionBound<$ExpectedClientVersion> {
|
|
1626
|
+
osdkMetadata: typeof $osdkMetadata;
|
|
1627
|
+
${stringify(definition, {
|
|
1628
|
+
osdkMetadata: () => void 0,
|
|
1629
|
+
type: () => void 0,
|
|
1630
|
+
apiName: () => void 0,
|
|
1631
|
+
links: (_value) => `{
|
|
1632
|
+
${stringify(definition.links, {
|
|
1633
|
+
"*": (definition2) => `ObjectTypeLinkDefinition<${getObjectDefIdentifier(definition2.targetType, v2)}, ${definition2.multiplicity}>`
|
|
1634
|
+
})}
|
|
1635
|
+
}`,
|
|
1636
|
+
properties: (_value) => `{
|
|
1637
|
+
${stringify(definition.properties, {
|
|
1638
|
+
"*": (propertyDefinition) => `PropertyDef<"${propertyDefinition.type}", "${propertyDefinition.nullable ? "nullable" : "non-nullable"}", "${propertyDefinition.multiplicity ? "array" : "single"}">`
|
|
1639
|
+
})}
|
|
1640
|
+
}`
|
|
1641
|
+
})}
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
`;
|
|
1645
|
+
}
|
|
1646
|
+
const imports = [];
|
|
1647
|
+
return `${imports.join("\n")}
|
|
1648
|
+
|
|
1649
|
+
${v2 ? getV2Types() : ""}
|
|
1650
|
+
|
|
1651
|
+
export const ${definition.apiName}: ${objectDefIdentifier} = {
|
|
1652
|
+
osdkMetadata: $osdkMetadata,
|
|
1653
|
+
${stringify(definition, {
|
|
1654
|
+
osdkMetadata: () => void 0
|
|
1655
|
+
})}
|
|
1656
|
+
|
|
1657
|
+
};`;
|
|
1658
|
+
}
|
|
1659
|
+
var ExpectedOsdkVersion = "0.19.0";
|
|
1660
|
+
async function generateOntologyMetadataFile(ontology, userAgent, fs2, outDir) {
|
|
1661
|
+
fs2.writeFile(path16__default.join(outDir, "OntologyMetadata.ts"), await formatTs(`
|
|
1662
|
+
import { OntologyMetadata as OM } from "@osdk/api";
|
|
1663
|
+
|
|
1664
|
+
export type $ExpectedClientVersion = "${ExpectedOsdkVersion}";
|
|
1665
|
+
export const $osdkMetadata = { extraUserAgent: "${userAgent}" };
|
|
1666
|
+
|
|
1667
|
+
export interface OntologyMetadata extends OM<$ExpectedClientVersion> {};
|
|
1668
|
+
|
|
1669
|
+
export const OntologyMetadata: OntologyMetadata = {
|
|
1670
|
+
expectsClientVersion: "${ExpectedOsdkVersion}",
|
|
1671
|
+
ontologyRid: "${ontology.ontology.rid}",
|
|
1672
|
+
ontologyApiName: "${ontology.ontology.apiName}",
|
|
1673
|
+
userAgent: "${userAgent}",
|
|
1674
|
+
};
|
|
1675
|
+
`));
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
// src/v2.0/generateClientSdkVersionTwoPointZero.ts
|
|
1679
|
+
async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs2, outDir, packageType = "commonjs") {
|
|
1680
|
+
await verifyOutdir(outDir, fs2);
|
|
1681
|
+
const sanitizedOntology = sanitizeMetadata(ontology);
|
|
1682
|
+
const objectNames = Object.keys(sanitizedOntology.objectTypes).sort((a, b) => a.localeCompare(b));
|
|
1683
|
+
const actionNames = Object.keys(sanitizedOntology.actionTypes).sort((a, b) => a.localeCompare(b));
|
|
1684
|
+
Object.keys(sanitizedOntology.queryTypes).sort((a, b) => a.localeCompare(b));
|
|
1685
|
+
const interfaceNames = Object.keys(sanitizedOntology.interfaceTypes ?? {}).sort((a, b) => a.localeCompare(b));
|
|
1686
|
+
const importExt = packageType === "module" ? ".js" : "";
|
|
1687
|
+
await fs2.mkdir(outDir, {
|
|
1688
|
+
recursive: true
|
|
1689
|
+
});
|
|
1690
|
+
fs2.writeFile(path16__default.join(outDir, "index.ts"), await formatTs(`
|
|
1691
|
+
export { Ontology } from "./Ontology${importExt}";
|
|
1692
|
+
export * from "./ontology/actions/index${importExt}";
|
|
1693
|
+
export * from "./ontology/objects${importExt}";
|
|
1694
|
+
export * from "./ontology/interfaces${importExt}";
|
|
1695
|
+
`));
|
|
1696
|
+
await generateOntologyMetadataFile(sanitizedOntology, userAgent, fs2, outDir);
|
|
1697
|
+
await fs2.writeFile(path16__default.join(outDir, "Ontology.ts"), await formatTs(`
|
|
1698
|
+
import type { OntologyDefinition } from "@osdk/api";
|
|
1699
|
+
import * as Actions from "./ontology/actions/index${importExt}";
|
|
1700
|
+
import * as Objects from "./ontology/objects${importExt}";
|
|
1701
|
+
import * as Interfaces from "./ontology/interfaces${importExt}";
|
|
1702
|
+
import { OntologyMetadata } from "./OntologyMetadata${importExt}";
|
|
1703
|
+
|
|
1704
|
+
const _Ontology = {
|
|
1705
|
+
metadata: OntologyMetadata,
|
|
1706
|
+
objects: {
|
|
1707
|
+
${objectNames.map((objectName) => {
|
|
1708
|
+
return `${objectName}: Objects.${objectName}`;
|
|
1709
|
+
}).join(",\n")}
|
|
1710
|
+
|
|
1711
|
+
},
|
|
1712
|
+
actions: {
|
|
1713
|
+
${actionNames.map((actionName) => {
|
|
1714
|
+
return `${actionName}: Actions.${actionName}`;
|
|
1715
|
+
}).join(",\n")}
|
|
1716
|
+
},
|
|
1717
|
+
queries: {
|
|
1718
|
+
// TODO
|
|
1719
|
+
},
|
|
1720
|
+
interfaces: {
|
|
1721
|
+
${interfaceNames.map((objectName) => {
|
|
1722
|
+
return `${objectName}: Interfaces.${objectName}`;
|
|
1723
|
+
}).join(",\n")}
|
|
1724
|
+
|
|
1725
|
+
}
|
|
1726
|
+
} satisfies OntologyDefinition<${stringUnionFrom2(objectNames)}>;
|
|
1727
|
+
|
|
1728
|
+
type _Ontology = typeof _Ontology;
|
|
1729
|
+
export interface Ontology extends _Ontology {}
|
|
1730
|
+
export const Ontology = _Ontology as Ontology;
|
|
1731
|
+
`));
|
|
1732
|
+
await fs2.mkdir(path16__default.join(outDir, "ontology", "objects"), {
|
|
1733
|
+
recursive: true
|
|
1734
|
+
});
|
|
1735
|
+
for (const name of objectNames) {
|
|
1736
|
+
const obj = ontology.objectTypes[name];
|
|
1737
|
+
await fs2.writeFile(path16__default.join(outDir, "ontology", `objects`, `${name}.ts`), await formatTs(`
|
|
1738
|
+
import type { ObjectTypeDefinition, VersionBound, ObjectTypeLinkDefinition, PropertyDef } from "@osdk/api";
|
|
1739
|
+
import { Osdk } from "@osdk/client";
|
|
1740
|
+
import { $osdkMetadata } from "../../OntologyMetadata${importExt}";
|
|
1741
|
+
import type { $ExpectedClientVersion } from "../../OntologyMetadata${importExt}";
|
|
1742
|
+
|
|
1743
|
+
${wireObjectTypeV2ToSdkObjectConst(obj, importExt, true)}
|
|
1744
|
+
`));
|
|
1745
|
+
}
|
|
1746
|
+
await generateOntologyInterfaces(fs2, outDir, interfaceNames, ontology, importExt);
|
|
1747
|
+
const actionsDir = path16__default.join(outDir, "ontology", "actions");
|
|
1748
|
+
await fs2.mkdir(actionsDir, {
|
|
1749
|
+
recursive: true
|
|
1750
|
+
});
|
|
1751
|
+
await generatePerActionDataFiles(sanitizedOntology, fs2, actionsDir, importExt, true);
|
|
1752
|
+
await fs2.writeFile(path16__default.join(outDir, "ontology", "objects.ts"), await formatTs(`
|
|
1753
|
+
${Object.keys(ontology.objectTypes).sort((a, b) => a.localeCompare(b)).map((apiName) => `export * from "./objects/${apiName}${importExt}";`).join("\n")}
|
|
1754
|
+
${Object.keys(ontology.objectTypes).length === 0 ? "export {};" : ""}
|
|
1755
|
+
`));
|
|
1756
|
+
}
|
|
1757
|
+
function stringUnionFrom2(values) {
|
|
1758
|
+
if (values.length === 0) {
|
|
1759
|
+
return "never";
|
|
1760
|
+
} else {
|
|
1761
|
+
return values.map((v) => `"${v}"`).join("|");
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
async function generateOntologyInterfaces(fs2, outDir, interfaceNames, ontology, importExt) {
|
|
1765
|
+
const interfacesDir = path16__default.join(outDir, "ontology", "interfaces");
|
|
1766
|
+
await fs2.mkdir(interfacesDir, {
|
|
1767
|
+
recursive: true
|
|
1768
|
+
});
|
|
1769
|
+
for (const name of interfaceNames) {
|
|
1770
|
+
const obj = ontology.interfaceTypes[name];
|
|
1771
|
+
await fs2.writeFile(path16__default.join(interfacesDir, `${name}.ts`), await formatTs(`
|
|
1772
|
+
|
|
1773
|
+
import type { InterfaceDefinition, PropertyDef, VersionBound } from "@osdk/api";
|
|
1774
|
+
import { $osdkMetadata, $expectedClientVersion } from "../../OntologyMetadata${importExt}";
|
|
1775
|
+
import type { $ExpectedClientVersion } from "../../OntologyMetadata${importExt}";
|
|
1776
|
+
|
|
1777
|
+
${__UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(obj, true)}
|
|
1778
|
+
`));
|
|
1779
|
+
}
|
|
1780
|
+
await fs2.writeFile(interfacesDir + ".ts", await formatTs(`
|
|
1781
|
+
${Object.keys(ontology.interfaceTypes ?? {}).map((apiName) => `export * from "./interfaces/${apiName}${importExt}";`).join("\n")}
|
|
1782
|
+
${Object.keys(ontology.interfaceTypes ?? {}).length === 0 ? "export {}" : ""}
|
|
1783
|
+
`));
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
// src/generateClientSdkPackage.ts
|
|
1787
|
+
async function generateClientSdkPackage(packageName, packageVersion, sdkVersion, baseOutDir, ontology, minimalFs, dependencyVersions, cliVersion) {
|
|
1788
|
+
if (!packageName)
|
|
1789
|
+
throw new Error("Package name is require");
|
|
1790
|
+
for (const packageType of ["module", "commonjs"]) {
|
|
1791
|
+
const outDir = path16.join(baseOutDir, "dist", packageType);
|
|
1792
|
+
await (sdkVersion === "1.1" ? generateClientSdkVersionOneDotOne : sdkVersion === "2.0" ? generateClientSdkVersionTwoPointZero : void 0)(ontology, `typescript-sdk/${packageVersion} osdk-cli/${cliVersion}`, minimalFs, outDir, packageType);
|
|
1793
|
+
await fs.promises.mkdir(outDir, {
|
|
1794
|
+
recursive: true
|
|
1795
|
+
});
|
|
1796
|
+
await writeJson(minimalFs, path16.join(outDir, "package.json"), {
|
|
1797
|
+
type: packageType
|
|
1798
|
+
});
|
|
1799
|
+
await writeJson(minimalFs, path16.join(outDir, `tsconfig.json`), {
|
|
1800
|
+
compilerOptions: getTsCompilerOptions(packageType)
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
await writeJson(minimalFs, path16.join(baseOutDir, "package.json"), await getPackageJsonContents(packageName, packageVersion, sdkVersion, dependencyVersions));
|
|
1804
|
+
await minimalFs.mkdir(path16.join(baseOutDir, "ontology"), {
|
|
1805
|
+
recursive: true
|
|
1806
|
+
});
|
|
1807
|
+
await minimalFs.writeFile(path16.join(baseOutDir, "ontology", "objects.js"), `module.exports = require("../../dist/module/ontology/objects")`);
|
|
1808
|
+
await minimalFs.writeFile(path16.join(baseOutDir, "ontology", "objects.d.ts"), `export * from "../dist/module/ontology/objects"`);
|
|
1809
|
+
}
|
|
1810
|
+
function getTsCompilerOptions(packageType) {
|
|
1811
|
+
const commonTsconfig = {
|
|
1812
|
+
importHelpers: true,
|
|
1813
|
+
declaration: true,
|
|
1814
|
+
isolatedModules: true,
|
|
1815
|
+
esModuleInterop: true,
|
|
1816
|
+
forceConsistentCasingInFileNames: true,
|
|
1817
|
+
strict: true,
|
|
1818
|
+
skipLibCheck: true
|
|
1819
|
+
};
|
|
1820
|
+
const compilerOptions = packageType === "commonjs" ? {
|
|
1821
|
+
...commonTsconfig,
|
|
1822
|
+
module: "commonjs",
|
|
1823
|
+
target: "es2018"
|
|
1824
|
+
} : {
|
|
1825
|
+
...commonTsconfig,
|
|
1826
|
+
module: "NodeNext",
|
|
1827
|
+
target: "ES2020"
|
|
1828
|
+
};
|
|
1829
|
+
return compilerOptions;
|
|
1830
|
+
}
|
|
1831
|
+
function getPackageJsonContents(name, version, sdkVersion, {
|
|
1832
|
+
typescriptVersion,
|
|
1833
|
+
tslibVersion,
|
|
1834
|
+
areTheTypesWrongVersion,
|
|
1835
|
+
osdkApiVersion,
|
|
1836
|
+
osdkClientVersion,
|
|
1837
|
+
osdkLegacyClientVersion
|
|
1838
|
+
}) {
|
|
1839
|
+
const esmPrefix = "./dist/module";
|
|
1840
|
+
const commonjsPrefix = "./dist/commonjs";
|
|
1841
|
+
return {
|
|
1842
|
+
name,
|
|
1843
|
+
version,
|
|
1844
|
+
main: `${commonjsPrefix}/index.js`,
|
|
1845
|
+
module: `${esmPrefix}/index.js`,
|
|
1846
|
+
exports: {
|
|
1847
|
+
".": {
|
|
1848
|
+
import: `${esmPrefix}/index.js`,
|
|
1849
|
+
require: `${commonjsPrefix}/index.js`
|
|
1850
|
+
},
|
|
1851
|
+
"./ontology/objects": {
|
|
1852
|
+
import: `${esmPrefix}/ontology/objects${sdkVersion === "2.0" ? "" : "/index"}.js`,
|
|
1853
|
+
require: `${commonjsPrefix}/ontology/objects${sdkVersion === "2.0" ? "" : "/index"}.js`
|
|
1854
|
+
}
|
|
1855
|
+
},
|
|
1856
|
+
scripts: {
|
|
1857
|
+
prepack: `tsc -p ${esmPrefix}/tsconfig.json && tsc -p ${commonjsPrefix}/tsconfig.json`,
|
|
1858
|
+
check: "npm exec attw $(npm pack)"
|
|
1859
|
+
},
|
|
1860
|
+
devDependencies: {
|
|
1861
|
+
"typescript": typescriptVersion,
|
|
1862
|
+
"tslib": tslibVersion,
|
|
1863
|
+
"@arethetypeswrong/cli": areTheTypesWrongVersion,
|
|
1864
|
+
"@osdk/api": osdkApiVersion,
|
|
1865
|
+
...sdkVersion === "2.0" ? {
|
|
1866
|
+
"@osdk/client": osdkClientVersion
|
|
1867
|
+
} : {
|
|
1868
|
+
"@osdk/legacy-client": osdkLegacyClientVersion
|
|
1869
|
+
}
|
|
1870
|
+
},
|
|
1871
|
+
peerDependencies: {
|
|
1872
|
+
"@osdk/api": osdkApiVersion,
|
|
1873
|
+
...sdkVersion === "2.0" ? {
|
|
1874
|
+
"@osdk/client": osdkClientVersion
|
|
1875
|
+
} : {
|
|
1876
|
+
"@osdk/legacy-client": osdkLegacyClientVersion
|
|
1877
|
+
}
|
|
1878
|
+
},
|
|
1879
|
+
files: ["**/*.js", "**/*.d.ts", "dist/**/package.json"]
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
async function writeJson(minimalFs, filePath, body) {
|
|
1883
|
+
return await minimalFs.writeFile(filePath, JSON.stringify(body, void 0, 2) + "\n");
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
export { generateClientSdkPackage as __UNSTABLE_generateClientSdkPackage, generateClientSdkVersionOneDotOne, generateClientSdkVersionTwoPointZero };
|
|
1887
|
+
//# sourceMappingURL=out.js.map
|
|
1888
|
+
//# sourceMappingURL=index.browser.mjs.map
|