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