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