@osdk/generator 1.13.0 → 1.14.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/build/browser/index.js +1835 -981
- package/build/browser/index.js.map +1 -1
- package/build/cjs/GenerateContext/EnhanceCommon.d.cts +9 -0
- package/build/cjs/GenerateContext/EnhanceCommon.d.ts.map +1 -0
- package/build/cjs/GenerateContext/EnhancedAction.d.cts +14 -0
- package/build/cjs/GenerateContext/EnhancedAction.d.ts.map +1 -0
- package/build/cjs/GenerateContext/EnhancedBase.d.cts +23 -0
- package/build/cjs/GenerateContext/EnhancedBase.d.ts.map +1 -0
- package/build/cjs/GenerateContext/EnhancedInterfaceType.d.cts +13 -0
- package/build/cjs/GenerateContext/EnhancedInterfaceType.d.ts.map +1 -0
- package/build/cjs/GenerateContext/EnhancedObjectType.d.cts +12 -0
- package/build/cjs/GenerateContext/EnhancedObjectType.d.ts.map +1 -0
- package/build/cjs/GenerateContext/EnhancedOntologyDefinition.d.cts +27 -0
- package/build/cjs/GenerateContext/EnhancedOntologyDefinition.d.ts.map +1 -0
- package/build/cjs/GenerateContext/EnhancedQuery.d.cts +14 -0
- package/build/cjs/GenerateContext/EnhancedQuery.d.ts.map +1 -0
- package/build/cjs/GenerateContext/EnhancedSharedPropertyType.d.cts +8 -0
- package/build/cjs/GenerateContext/EnhancedSharedPropertyType.d.ts.map +1 -0
- package/build/cjs/GenerateContext/ForeignType.d.cts +10 -0
- package/build/cjs/GenerateContext/ForeignType.d.ts.map +1 -0
- package/build/cjs/GenerateContext/GenerateContext.d.cts +13 -0
- package/build/cjs/GenerateContext/GenerateContext.d.ts.map +1 -0
- package/build/cjs/GenerateContext/enhanceOntology.d.cts +4 -0
- package/build/cjs/GenerateContext/enhanceOntology.d.ts.map +1 -0
- package/build/cjs/generateClientSdkPackage.d.cts +1 -1
- package/build/cjs/generateClientSdkPackage.d.ts.map +1 -1
- package/build/cjs/index.cjs +1835 -981
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/shared/apiNamespaces/startsWithApiNamespace.d.cts +2 -0
- package/build/cjs/shared/apiNamespaces/startsWithApiNamespace.d.ts.map +1 -0
- package/build/cjs/shared/apiNamespaces/startsWithApiNamespace.test.d.cts +2 -0
- package/build/cjs/shared/apiNamespaces/startsWithApiNamespace.test.d.ts.map +1 -0
- package/build/cjs/shared/getObjectImports.d.cts +4 -0
- package/build/cjs/shared/getObjectImports.d.ts.map +1 -0
- package/build/cjs/shared/getObjectTypeApiNamesFromQuery.d.cts +4 -0
- package/build/cjs/shared/getObjectTypeApiNamesFromQuery.d.ts.map +1 -0
- package/build/cjs/shared/getObjectTypesFromQueryDataType.d.cts +3 -0
- package/build/cjs/shared/getObjectTypesFromQueryDataType.d.ts.map +1 -0
- package/build/cjs/shared/wireQueryDataTypeToQueryDataTypeDefinition.d.ts.map +1 -1
- package/build/cjs/util/stringUnionFrom.d.cts +2 -0
- package/build/cjs/util/stringUnionFrom.d.ts.map +1 -0
- package/build/cjs/util/test/TodoWireOntology.d.cts +60 -4
- package/build/cjs/util/test/TodoWireOntology.d.ts.map +1 -1
- package/build/cjs/util/test/createMockMinimalFiles.d.ts.map +1 -1
- package/build/cjs/util/test/formatTs.d.cts +1 -1
- package/build/cjs/util/test/formatTs.d.ts.map +1 -1
- package/build/cjs/v1.1/generateClientSdkVersionOneDotOne.d.ts.map +1 -1
- package/build/cjs/v1.1/generatePerActionDataFilesV1.d.cts +3 -0
- package/build/cjs/v1.1/generatePerActionDataFilesV1.d.ts.map +1 -0
- package/build/cjs/v1.1/generatePerActionDataFilesV1.test.d.cts +2 -0
- package/build/cjs/v1.1/generatePerActionDataFilesV1.test.d.ts.map +1 -0
- package/build/cjs/v1.1/generatePerObjectInterfaceAndDataFiles.d.cts +2 -2
- package/build/cjs/v1.1/generatePerObjectInterfaceAndDataFiles.d.ts.map +1 -1
- package/build/cjs/v1.1/generatePerQueryDataFiles.d.cts +3 -3
- package/build/cjs/v1.1/generatePerQueryDataFiles.d.ts.map +1 -1
- package/build/cjs/v1.1/wireObjectTypeV2ToSdkObjectConstV1.d.cts +2 -0
- package/build/cjs/v1.1/wireObjectTypeV2ToSdkObjectConstV1.d.ts.map +1 -0
- package/build/cjs/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.d.ts.map +1 -0
- package/build/cjs/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.d.ts.map +1 -0
- package/build/cjs/v2.0/generateClientSdkVersionTwoPointZero.d.cts +1 -1
- package/build/cjs/v2.0/generateClientSdkVersionTwoPointZero.d.ts.map +1 -1
- package/build/cjs/v2.0/generateMetadata.d.cts +2 -3
- package/build/cjs/v2.0/generateMetadata.d.ts.map +1 -1
- package/build/cjs/v2.0/generatePerActionDataFiles.d.cts +3 -0
- package/build/cjs/v2.0/generatePerActionDataFiles.d.ts.map +1 -0
- package/build/cjs/v2.0/generatePerActionDataFiles.test.d.ts.map +1 -0
- package/build/cjs/v2.0/generatePerQueryDataFiles.d.cts +9 -0
- package/build/cjs/v2.0/generatePerQueryDataFiles.d.ts.map +1 -0
- package/build/cjs/v2.0/generatePerQueryDataFiles.test.d.cts +2 -0
- package/build/cjs/v2.0/generatePerQueryDataFiles.test.d.ts.map +1 -0
- package/build/cjs/v2.0/wireObjectTypeV2ToSdkObjectConstV2.d.cts +13 -0
- package/build/cjs/v2.0/wireObjectTypeV2ToSdkObjectConstV2.d.ts.map +1 -0
- package/build/esm/GenerateContext/EnhanceCommon.d.ts +9 -0
- package/build/esm/GenerateContext/EnhanceCommon.d.ts.map +1 -0
- package/build/esm/GenerateContext/EnhancedAction.d.ts +14 -0
- package/build/esm/GenerateContext/EnhancedAction.d.ts.map +1 -0
- package/build/esm/GenerateContext/EnhancedBase.d.ts +23 -0
- package/build/esm/GenerateContext/EnhancedBase.d.ts.map +1 -0
- package/build/esm/GenerateContext/EnhancedInterfaceType.d.ts +13 -0
- package/build/esm/GenerateContext/EnhancedInterfaceType.d.ts.map +1 -0
- package/build/esm/GenerateContext/EnhancedObjectType.d.ts +12 -0
- package/build/esm/GenerateContext/EnhancedObjectType.d.ts.map +1 -0
- package/build/esm/GenerateContext/EnhancedOntologyDefinition.d.ts +27 -0
- package/build/esm/GenerateContext/EnhancedOntologyDefinition.d.ts.map +1 -0
- package/build/esm/GenerateContext/EnhancedQuery.d.ts +14 -0
- package/build/esm/GenerateContext/EnhancedQuery.d.ts.map +1 -0
- package/build/esm/GenerateContext/EnhancedSharedPropertyType.d.ts +8 -0
- package/build/esm/GenerateContext/EnhancedSharedPropertyType.d.ts.map +1 -0
- package/build/esm/GenerateContext/ForeignType.d.ts +10 -0
- package/build/esm/GenerateContext/ForeignType.d.ts.map +1 -0
- package/build/esm/GenerateContext/GenerateContext.d.ts +13 -0
- package/build/esm/GenerateContext/GenerateContext.d.ts.map +1 -0
- package/build/esm/GenerateContext/enhanceOntology.d.ts +4 -0
- package/build/esm/GenerateContext/enhanceOntology.d.ts.map +1 -0
- package/build/esm/generateClientSdkPackage.d.ts +1 -1
- package/build/esm/generateClientSdkPackage.d.ts.map +1 -1
- package/build/esm/index.js +1835 -981
- package/build/esm/index.js.map +1 -1
- package/build/esm/shared/apiNamespaces/startsWithApiNamespace.d.ts +2 -0
- package/build/esm/shared/apiNamespaces/startsWithApiNamespace.d.ts.map +1 -0
- package/build/esm/shared/apiNamespaces/startsWithApiNamespace.test.d.ts +2 -0
- package/build/esm/shared/apiNamespaces/startsWithApiNamespace.test.d.ts.map +1 -0
- package/build/esm/shared/getObjectImports.d.ts +4 -0
- package/build/esm/shared/getObjectImports.d.ts.map +1 -0
- package/build/esm/shared/getObjectTypeApiNamesFromQuery.d.ts +4 -0
- package/build/esm/shared/getObjectTypeApiNamesFromQuery.d.ts.map +1 -0
- package/build/esm/shared/getObjectTypesFromQueryDataType.d.ts +3 -0
- package/build/esm/shared/getObjectTypesFromQueryDataType.d.ts.map +1 -0
- package/build/esm/shared/wireQueryDataTypeToQueryDataTypeDefinition.d.ts.map +1 -1
- package/build/esm/util/stringUnionFrom.d.ts +2 -0
- package/build/esm/util/stringUnionFrom.d.ts.map +1 -0
- package/build/esm/util/test/TodoWireOntology.d.ts +60 -4
- package/build/esm/util/test/TodoWireOntology.d.ts.map +1 -1
- package/build/esm/util/test/createMockMinimalFiles.d.ts.map +1 -1
- package/build/esm/util/test/formatTs.d.ts +1 -1
- package/build/esm/util/test/formatTs.d.ts.map +1 -1
- package/build/esm/v1.1/generateClientSdkVersionOneDotOne.d.ts.map +1 -1
- package/build/esm/v1.1/generatePerActionDataFilesV1.d.ts +3 -0
- package/build/esm/v1.1/generatePerActionDataFilesV1.d.ts.map +1 -0
- package/build/esm/v1.1/generatePerActionDataFilesV1.test.d.ts +2 -0
- package/build/esm/v1.1/generatePerActionDataFilesV1.test.d.ts.map +1 -0
- package/build/esm/v1.1/generatePerObjectInterfaceAndDataFiles.d.ts +2 -2
- package/build/esm/v1.1/generatePerObjectInterfaceAndDataFiles.d.ts.map +1 -1
- package/build/esm/v1.1/generatePerQueryDataFiles.d.ts +3 -3
- package/build/esm/v1.1/generatePerQueryDataFiles.d.ts.map +1 -1
- package/build/esm/v1.1/wireObjectTypeV2ToSdkObjectConstV1.d.ts +2 -0
- package/build/esm/v1.1/wireObjectTypeV2ToSdkObjectConstV1.d.ts.map +1 -0
- package/build/esm/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.d.ts.map +1 -0
- package/build/esm/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.d.ts.map +1 -0
- package/build/esm/v2.0/generateClientSdkVersionTwoPointZero.d.ts +1 -1
- package/build/esm/v2.0/generateClientSdkVersionTwoPointZero.d.ts.map +1 -1
- package/build/esm/v2.0/generateMetadata.d.ts +2 -3
- package/build/esm/v2.0/generateMetadata.d.ts.map +1 -1
- package/build/esm/v2.0/generatePerActionDataFiles.d.ts +3 -0
- package/build/esm/v2.0/generatePerActionDataFiles.d.ts.map +1 -0
- package/build/esm/v2.0/generatePerActionDataFiles.test.d.ts.map +1 -0
- package/build/esm/v2.0/generatePerQueryDataFiles.d.ts +9 -0
- package/build/esm/v2.0/generatePerQueryDataFiles.d.ts.map +1 -0
- package/build/esm/v2.0/generatePerQueryDataFiles.test.d.ts +2 -0
- package/build/esm/v2.0/generatePerQueryDataFiles.test.d.ts.map +1 -0
- package/build/esm/v2.0/wireObjectTypeV2ToSdkObjectConstV2.d.ts +13 -0
- package/build/esm/v2.0/wireObjectTypeV2ToSdkObjectConstV2.d.ts.map +1 -0
- package/package.json +5 -4
- package/build/cjs/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.d.ts.map +0 -1
- package/build/cjs/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.d.ts.map +0 -1
- package/build/cjs/shared/generatePerActionDataFiles.d.cts +0 -4
- package/build/cjs/shared/generatePerActionDataFiles.d.ts.map +0 -1
- package/build/cjs/shared/generatePerActionDataFiles.test.d.ts.map +0 -1
- package/build/cjs/shared/wireObjectTypeV2ToSdkObjectConst.d.cts +0 -2
- package/build/cjs/shared/wireObjectTypeV2ToSdkObjectConst.d.ts.map +0 -1
- package/build/esm/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.d.ts.map +0 -1
- package/build/esm/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.d.ts.map +0 -1
- package/build/esm/shared/generatePerActionDataFiles.d.ts +0 -4
- package/build/esm/shared/generatePerActionDataFiles.d.ts.map +0 -1
- package/build/esm/shared/generatePerActionDataFiles.test.d.ts.map +0 -1
- package/build/esm/shared/wireObjectTypeV2ToSdkObjectConst.d.ts +0 -2
- package/build/esm/shared/wireObjectTypeV2ToSdkObjectConst.d.ts.map +0 -1
- /package/build/cjs/{shared → v2.0}/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.d.cts +0 -0
- /package/build/cjs/{shared → v2.0}/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.d.cts +0 -0
- /package/build/cjs/{shared → v2.0}/generatePerActionDataFiles.test.d.cts +0 -0
- /package/build/esm/{shared → v2.0}/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.d.ts +0 -0
- /package/build/esm/{shared → v2.0}/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.d.ts +0 -0
- /package/build/esm/{shared → v2.0}/generatePerActionDataFiles.test.d.ts +0 -0
package/build/cjs/index.cjs
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var fs = require('fs');
|
|
4
4
|
var path16 = require('path');
|
|
5
|
+
var generatorConverters = require('@osdk/generator-converters');
|
|
5
6
|
var prettier = require('prettier');
|
|
6
7
|
var organizeImports = require('prettier-plugin-organize-imports');
|
|
7
|
-
var generatorConverters = require('@osdk/generator-converters');
|
|
8
8
|
var fastDeepEqual = require('fast-deep-equal');
|
|
9
9
|
var invariant = require('tiny-invariant');
|
|
10
10
|
|
|
@@ -35,129 +35,250 @@ var fastDeepEqual__default = /*#__PURE__*/_interopDefault(fastDeepEqual);
|
|
|
35
35
|
var invariant__default = /*#__PURE__*/_interopDefault(invariant);
|
|
36
36
|
|
|
37
37
|
// src/generateClientSdkPackage.ts
|
|
38
|
+
var AbstractImportable = class {
|
|
39
|
+
/**
|
|
40
|
+
* Either a path relative to the ourDir (e.g. "./ontology/objects/foo.js") or a normal
|
|
41
|
+
* module import (e.g. "@something/foo")/
|
|
42
|
+
*/
|
|
43
|
+
constructor(common, fullApiName, basePath) {
|
|
44
|
+
this._common = common;
|
|
45
|
+
this.fullApiName = fullApiName;
|
|
46
|
+
[this.apiNamespace, this.shortApiName] = extractNamespace(this.fullApiName);
|
|
47
|
+
const {
|
|
48
|
+
ontologyApiNamespace,
|
|
49
|
+
apiNamespacePackageMap,
|
|
50
|
+
importExt
|
|
51
|
+
} = common;
|
|
52
|
+
this.isLocal = ontologyApiNamespace === this.apiNamespace;
|
|
53
|
+
this.sourcePackage = this.apiNamespace && !this.isLocal ? apiNamespacePackageMap.get(this.apiNamespace) : void 0;
|
|
54
|
+
this.importPath = this.isLocal ? `${basePath}/${this.shortApiName}${importExt}` : this.sourcePackage;
|
|
55
|
+
this.uniqueImportName = this.shortApiName;
|
|
56
|
+
}
|
|
57
|
+
getImportPathRelTo = (filePath) => {
|
|
58
|
+
if (this.importPath.startsWith(".")) {
|
|
59
|
+
const result = path16__namespace.relative(path16__namespace.dirname(filePath), this.importPath);
|
|
60
|
+
if (result.startsWith(".")) {
|
|
61
|
+
return result;
|
|
62
|
+
} else {
|
|
63
|
+
return `./${result}`;
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
return this.importPath;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
var EnhancedBase = class extends AbstractImportable {
|
|
71
|
+
constructor(common, og, fullApiName, basePath) {
|
|
72
|
+
super(common, fullApiName, basePath);
|
|
73
|
+
this.og = og;
|
|
74
|
+
if (!this.isLocal && !this.sourcePackage) {
|
|
75
|
+
throw new Error(`Expected { ns:'${this.apiNamespace}', shortName: '${this.shortApiName}'} to be in namespace '${common.ontologyApiNamespace}' or in a provided package mapping`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
function extractNamespace(fqApiName) {
|
|
80
|
+
const last = fqApiName.lastIndexOf(".");
|
|
81
|
+
if (last === -1) return [void 0, fqApiName];
|
|
82
|
+
return [fqApiName.slice(0, last), fqApiName.slice(last + 1)];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/GenerateContext/EnhancedAction.ts
|
|
86
|
+
var EnhancedAction = class extends EnhancedBase {
|
|
87
|
+
constructor(common, og) {
|
|
88
|
+
super(common, og, og.apiName, "./ontology/actions");
|
|
89
|
+
this.og = og;
|
|
90
|
+
}
|
|
91
|
+
get description() {
|
|
92
|
+
return this.og.description;
|
|
93
|
+
}
|
|
94
|
+
get parameters() {
|
|
95
|
+
return this.og.parameters;
|
|
96
|
+
}
|
|
97
|
+
get operations() {
|
|
98
|
+
return this.og.operations;
|
|
99
|
+
}
|
|
100
|
+
get paramsIdentifier() {
|
|
101
|
+
return `${this.shortApiName}.Parameters`;
|
|
102
|
+
}
|
|
103
|
+
get definitionIdentifier() {
|
|
104
|
+
return `${this.shortApiName}.Definition`;
|
|
105
|
+
}
|
|
106
|
+
get definitionParamsIdentifier() {
|
|
107
|
+
return `${this.shortApiName}.ParamsDefinition`;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
38
110
|
|
|
39
111
|
// src/util/deleteUndefineds.ts
|
|
40
112
|
function deleteUndefineds(obj) {
|
|
41
113
|
return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== void 0));
|
|
42
114
|
}
|
|
43
115
|
|
|
44
|
-
// src/
|
|
45
|
-
var
|
|
46
|
-
|
|
116
|
+
// src/GenerateContext/EnhancedInterfaceType.ts
|
|
117
|
+
var EnhancedInterfaceType = class extends EnhancedBase {
|
|
118
|
+
constructor(common, og) {
|
|
119
|
+
super(common, og, og.apiName, "./ontology/interfaces");
|
|
120
|
+
this.og = og;
|
|
121
|
+
}
|
|
122
|
+
getDefinitionIdentifier(v2) {
|
|
123
|
+
return v2 ? this.shortApiName : `${this.shortApiName}Def`;
|
|
124
|
+
}
|
|
125
|
+
getImportedDefinitionIdentifier(v2) {
|
|
126
|
+
return this.getDefinitionIdentifier(v2);
|
|
127
|
+
}
|
|
128
|
+
get properties() {
|
|
129
|
+
return this.og.properties;
|
|
130
|
+
}
|
|
131
|
+
getCleanedUpDefinition(v2) {
|
|
132
|
+
return deleteUndefineds(generatorConverters.__UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(this.og, v2));
|
|
133
|
+
}
|
|
47
134
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
for (const key of sortedKeys) {
|
|
53
|
-
const value = obj[key];
|
|
54
|
-
const res = (customizer[key] ?? customizer["*"] ?? defaultCustomizer)(value, (value2) => JSON.stringify(value2, null, 2), key, defaultKeyFormatter);
|
|
55
|
-
if (res) {
|
|
56
|
-
if (typeof res === "string") {
|
|
57
|
-
entries.push(`${defaultKeyFormatter(key)}: ${res}`);
|
|
58
|
-
} else {
|
|
59
|
-
entries.push(`${res[0]}: ${res[1]}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
135
|
+
var EnhancedObjectType = class extends EnhancedBase {
|
|
136
|
+
constructor(common, og) {
|
|
137
|
+
super(common, og, og.objectType.apiName, "./ontology/objects");
|
|
138
|
+
this.og = og;
|
|
62
139
|
}
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
});
|
|
74
|
-
}
|
|
140
|
+
getDefinitionIdentifier(v2) {
|
|
141
|
+
return v2 ? `${this.shortApiName}` : `${this.shortApiName}Def`;
|
|
142
|
+
}
|
|
143
|
+
getImportedDefinitionIdentifier(v2) {
|
|
144
|
+
return this.getDefinitionIdentifier(v2);
|
|
145
|
+
}
|
|
146
|
+
getCleanedUpDefinition(v2) {
|
|
147
|
+
return deleteUndefineds(generatorConverters.wireObjectTypeFullMetadataToSdkObjectTypeDefinition(this.og, v2));
|
|
148
|
+
}
|
|
149
|
+
};
|
|
75
150
|
|
|
76
|
-
// src/
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
151
|
+
// src/GenerateContext/EnhancedQuery.ts
|
|
152
|
+
var EnhancedQuery = class extends EnhancedBase {
|
|
153
|
+
constructor(common, og) {
|
|
154
|
+
super(common, og, og.apiName, "./ontology/queries");
|
|
155
|
+
this.og = og;
|
|
156
|
+
}
|
|
157
|
+
get description() {
|
|
158
|
+
return this.og.description;
|
|
159
|
+
}
|
|
160
|
+
get parameters() {
|
|
161
|
+
return this.og.parameters;
|
|
162
|
+
}
|
|
163
|
+
get output() {
|
|
164
|
+
return this.og.output;
|
|
165
|
+
}
|
|
166
|
+
get paramsIdentifier() {
|
|
167
|
+
return `${this.shortApiName}.Parameters`;
|
|
168
|
+
}
|
|
169
|
+
get definitionIdentifier() {
|
|
170
|
+
return `${this.shortApiName}.Definition`;
|
|
171
|
+
}
|
|
172
|
+
get definitionParamsIdentifier() {
|
|
173
|
+
return `${this.definitionIdentifier}$Params`;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
81
176
|
|
|
82
|
-
// src/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
177
|
+
// src/GenerateContext/EnhancedSharedPropertyType.ts
|
|
178
|
+
var EnhancedSharedPropertyType = class extends EnhancedBase {
|
|
179
|
+
constructor(common, og) {
|
|
180
|
+
super(common, og, og.apiName, "./ontology/interfaces");
|
|
181
|
+
this.og = og;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
87
184
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
readonly ${propertyName}_: ${propertyType} | undefined`);
|
|
185
|
+
// src/GenerateContext/ForeignType.ts
|
|
186
|
+
var ForeignType = class extends AbstractImportable {
|
|
187
|
+
constructor(_common, type, apiNamespace, shortApiName) {
|
|
188
|
+
super(_common, `${apiNamespace}.${shortApiName}`, _common.apiNamespacePackageMap.get(apiNamespace));
|
|
189
|
+
this._common = _common;
|
|
190
|
+
this.type = type;
|
|
191
|
+
}
|
|
192
|
+
getImportedDefinitionIdentifier(v2) {
|
|
193
|
+
return `$Imported$${this.type}$${this.apiNamespace.replace(/\./g, "$")}$${this.shortApiName}`;
|
|
194
|
+
}
|
|
195
|
+
getDefinitionIdentifier(v2) {
|
|
196
|
+
if (this.type === "objectTypes") {
|
|
197
|
+
return v2 ? this.uniqueImportName : `${this.uniqueImportName}Def`;
|
|
198
|
+
} else {
|
|
199
|
+
return this.uniqueImportName;
|
|
104
200
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// src/GenerateContext/EnhancedOntologyDefinition.ts
|
|
205
|
+
var EnhancedOntologyDefinition = class {
|
|
206
|
+
constructor(original, ontologyApiNamespace, apiNamespacePackageMap, importExt) {
|
|
207
|
+
this.common = {
|
|
208
|
+
apiNamespacePackageMap,
|
|
209
|
+
enhancedOntology: this,
|
|
210
|
+
importExt,
|
|
211
|
+
ontologyApiNamespace
|
|
212
|
+
};
|
|
213
|
+
this.og = original;
|
|
214
|
+
this.ontology = original.ontology;
|
|
215
|
+
this.objectTypes = remap(original.objectTypes, this.common, EnhancedObjectType);
|
|
216
|
+
this.actionTypes = remap(original.actionTypes, this.common, EnhancedAction);
|
|
217
|
+
this.queryTypes = remap(original.queryTypes, this.common, EnhancedQuery);
|
|
218
|
+
this.interfaceTypes = remap(original.interfaceTypes, this.common, EnhancedInterfaceType);
|
|
219
|
+
this.sharedPropertyTypes = remap(original.sharedPropertyTypes, this.common, EnhancedSharedPropertyType);
|
|
220
|
+
}
|
|
221
|
+
#createRequireType = (type) => {
|
|
222
|
+
return (fullApiName, localOnly) => {
|
|
223
|
+
const ret = this[type][fullApiName];
|
|
224
|
+
if (!ret) {
|
|
225
|
+
const [apiNamespace, shortApiName] = extractNamespace(fullApiName);
|
|
226
|
+
if (localOnly || !apiNamespace) {
|
|
227
|
+
throw new Error(`Unable to find ${type}: No entry for '${fullApiName}`);
|
|
228
|
+
}
|
|
229
|
+
if (!this.common.apiNamespacePackageMap.has(apiNamespace)) {
|
|
230
|
+
throw new Error(`Unable to find ${type}: Unknown namespace '${apiNamespace}'`);
|
|
231
|
+
}
|
|
232
|
+
return new ForeignType(this.common, type, apiNamespace, shortApiName);
|
|
233
|
+
}
|
|
234
|
+
return ret;
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
requireObjectType = this.#createRequireType("objectTypes");
|
|
238
|
+
requireInterfaceType = this.#createRequireType("interfaceTypes");
|
|
239
|
+
requireActionType = this.#createRequireType("actionTypes");
|
|
240
|
+
requireQueryType = this.#createRequireType("queryTypes");
|
|
241
|
+
requireSharedPropertyType = this.#createRequireType("sharedPropertyTypes");
|
|
242
|
+
};
|
|
243
|
+
function remap(r, common, Constructor) {
|
|
244
|
+
return Object.fromEntries(Object.entries(r ?? {}).map(([fullApiName, v]) => {
|
|
245
|
+
return [fullApiName, new Constructor(common, v)];
|
|
246
|
+
}).sort((a, b) => a[0].localeCompare(b[0])));
|
|
111
247
|
}
|
|
112
|
-
|
|
248
|
+
|
|
249
|
+
// src/GenerateContext/enhanceOntology.ts
|
|
250
|
+
function enhanceOntology(sanitized, ontologyApiNamespace, apiNamespacePackageMap, importExt) {
|
|
251
|
+
return new EnhancedOntologyDefinition(sanitized, ontologyApiNamespace, apiNamespacePackageMap, importExt);
|
|
113
252
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
case "byte":
|
|
127
|
-
return "number";
|
|
128
|
-
case "date":
|
|
129
|
-
return "LocalDate";
|
|
130
|
-
case "decimal":
|
|
131
|
-
return "string";
|
|
132
|
-
case "double":
|
|
133
|
-
return "number";
|
|
134
|
-
case "float":
|
|
135
|
-
return "number";
|
|
136
|
-
case "geopoint":
|
|
137
|
-
return "GeoPoint";
|
|
138
|
-
case "geoshape":
|
|
139
|
-
return "GeoShape";
|
|
140
|
-
case "long":
|
|
141
|
-
return "StringLong";
|
|
142
|
-
case "short":
|
|
143
|
-
return "number";
|
|
144
|
-
case "timestamp":
|
|
145
|
-
return "Timestamp";
|
|
146
|
-
case "timeseries":
|
|
147
|
-
return property.itemType.type === "string" ? `TimeSeries<string>` : `TimeSeries<number>`;
|
|
148
|
-
case "marking":
|
|
149
|
-
return "string";
|
|
150
|
-
default:
|
|
151
|
-
throw new Error(`Unknown property type ${property}`);
|
|
152
|
-
}
|
|
253
|
+
|
|
254
|
+
// src/shared/sanitizeMetadata.ts
|
|
255
|
+
function sanitizeMetadata(ontology) {
|
|
256
|
+
return {
|
|
257
|
+
...ontology,
|
|
258
|
+
actionTypes: Object.fromEntries(Object.values(ontology.actionTypes).map((actionType) => {
|
|
259
|
+
return [camelize(actionType.apiName), {
|
|
260
|
+
...actionType,
|
|
261
|
+
apiName: camelize(actionType.apiName)
|
|
262
|
+
}];
|
|
263
|
+
}))
|
|
264
|
+
};
|
|
153
265
|
}
|
|
154
|
-
function
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
266
|
+
function camelize(name) {
|
|
267
|
+
return name.replace(/-./g, (segment) => segment[1].toUpperCase());
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// src/util/verifyOutDir.ts
|
|
271
|
+
async function verifyOutDir(outDir, fs2) {
|
|
272
|
+
try {
|
|
273
|
+
const contents = await fs2.readdir(outDir);
|
|
274
|
+
if (contents.length !== 0) {
|
|
275
|
+
throw new Error(`outDir ${outDir} is not empty, please delete its contents and try again`);
|
|
276
|
+
}
|
|
277
|
+
} catch (e) {
|
|
278
|
+
if (e.code === "ENOENT") ; else {
|
|
279
|
+
throw e;
|
|
280
|
+
}
|
|
159
281
|
}
|
|
160
|
-
return "";
|
|
161
282
|
}
|
|
162
283
|
|
|
163
284
|
// src/shared/getEditedEntities.ts
|
|
@@ -179,350 +300,24 @@ function getModifiedEntityTypes(action) {
|
|
|
179
300
|
modifiedObjects
|
|
180
301
|
};
|
|
181
302
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
multiplicity: value.dataType.type === "array",
|
|
198
|
-
type: actionPropertyToSdkPropertyDefinition(value.dataType.type === "array" ? value.dataType.subType : value.dataType),
|
|
199
|
-
nullable: !value.required,
|
|
200
|
-
description: value.description
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
function actionPropertyToSdkPropertyDefinition(parameterType) {
|
|
204
|
-
switch (parameterType.type) {
|
|
205
|
-
case "string":
|
|
206
|
-
case "boolean":
|
|
207
|
-
case "attachment":
|
|
208
|
-
case "double":
|
|
209
|
-
case "integer":
|
|
210
|
-
case "long":
|
|
211
|
-
case "timestamp":
|
|
212
|
-
case "marking":
|
|
213
|
-
return parameterType.type;
|
|
214
|
-
case "date":
|
|
215
|
-
return "datetime";
|
|
216
|
-
case "objectSet":
|
|
217
|
-
return {
|
|
218
|
-
type: "objectSet",
|
|
219
|
-
objectSet: parameterType.objectTypeApiName
|
|
220
|
-
};
|
|
221
|
-
case "object":
|
|
222
|
-
return {
|
|
223
|
-
type: "object",
|
|
224
|
-
object: parameterType.objectTypeApiName
|
|
225
|
-
};
|
|
226
|
-
case "array":
|
|
227
|
-
return actionPropertyToSdkPropertyDefinition(parameterType.subType);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
function createModifiedEntities(addedObjects, modifiedObjects) {
|
|
231
|
-
let entities = {};
|
|
232
|
-
for (const key of addedObjects) {
|
|
233
|
-
entities[key] = {
|
|
234
|
-
created: true,
|
|
235
|
-
modified: false
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
for (const key of modifiedObjects) {
|
|
239
|
-
if (entities[key]) {
|
|
240
|
-
entities[key].modified = true;
|
|
241
|
-
} else {
|
|
242
|
-
entities[key] = {
|
|
243
|
-
created: false,
|
|
244
|
-
modified: true
|
|
245
|
-
};
|
|
246
|
-
}
|
|
303
|
+
function formatTs(contents) {
|
|
304
|
+
try {
|
|
305
|
+
return prettier.format(contents, {
|
|
306
|
+
parser: "typescript",
|
|
307
|
+
singleQuote: true,
|
|
308
|
+
trailingComma: "all",
|
|
309
|
+
plugins: [organizeImports__default.default],
|
|
310
|
+
tabWidth: 2,
|
|
311
|
+
printWidth: 120
|
|
312
|
+
});
|
|
313
|
+
} catch (e) {
|
|
314
|
+
console.error("Failed to format file", e);
|
|
315
|
+
console.log(contents);
|
|
316
|
+
return contents;
|
|
247
317
|
}
|
|
248
|
-
return entities;
|
|
249
318
|
}
|
|
250
319
|
|
|
251
|
-
// src/
|
|
252
|
-
function propertyJsdoc(property, {
|
|
253
|
-
isInherited,
|
|
254
|
-
apiName
|
|
255
|
-
}) {
|
|
256
|
-
let ret = `/**
|
|
257
|
-
`;
|
|
258
|
-
const renderDisplayName = property.displayName && property.displayName !== apiName;
|
|
259
|
-
if (isInherited || renderDisplayName || property.description) {
|
|
260
|
-
if (isInherited) {
|
|
261
|
-
ret += ` * (inherited from parent)
|
|
262
|
-
`;
|
|
263
|
-
}
|
|
264
|
-
if (renderDisplayName) {
|
|
265
|
-
ret += ` * display name: '${property.displayName}'${property.description ? "," : ""}
|
|
266
|
-
`;
|
|
267
|
-
}
|
|
268
|
-
if (property.description) {
|
|
269
|
-
ret += ` * description: ${property.description}
|
|
270
|
-
`;
|
|
271
|
-
}
|
|
272
|
-
} else {
|
|
273
|
-
ret += ` * (no ontology metadata)
|
|
274
|
-
`;
|
|
275
|
-
}
|
|
276
|
-
ret += ` */
|
|
277
|
-
`;
|
|
278
|
-
return ret;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// src/shared/wireObjectTypeV2ToSdkObjectConst.ts
|
|
282
|
-
function getObjectDefIdentifier(name, v2) {
|
|
283
|
-
return v2 ? name : `${name}Def`;
|
|
284
|
-
}
|
|
285
|
-
function wireObjectTypeV2ToSdkObjectConst(object, importExt, v2 = false) {
|
|
286
|
-
const uniqueLinkTargetTypes = new Set(object.linkTypes.map((a) => a.objectTypeApiName));
|
|
287
|
-
const definition = deleteUndefineds(generatorConverters.wireObjectTypeFullMetadataToSdkObjectTypeDefinition(object, v2));
|
|
288
|
-
const objectDefIdentifier = getObjectDefIdentifier(object.objectType.apiName, v2);
|
|
289
|
-
function getV1Types() {
|
|
290
|
-
return `
|
|
291
|
-
export interface ${objectDefIdentifier} extends ObjectTypeDefinition<"${object.objectType.apiName}", ${object.objectType.apiName}> {
|
|
292
|
-
${stringify(definition, {
|
|
293
|
-
osdkMetadata: () => void 0,
|
|
294
|
-
// not used in v1
|
|
295
|
-
links: (_value) => `{
|
|
296
|
-
${stringify(definition.links, {
|
|
297
|
-
"*": (definition2) => `ObjectTypeLinkDefinition<${getObjectDefIdentifier(definition2.targetType, v2)}, ${definition2.multiplicity}>`
|
|
298
|
-
})}
|
|
299
|
-
}`
|
|
300
|
-
})}
|
|
301
|
-
}
|
|
302
|
-
`;
|
|
303
|
-
}
|
|
304
|
-
function getV2Types() {
|
|
305
|
-
return `
|
|
306
|
-
export interface ${objectDefIdentifier} extends ObjectTypeDefinition<"${object.objectType.apiName}", ${object.objectType.apiName}>, VersionBound<$ExpectedClientVersion> {
|
|
307
|
-
osdkMetadata: typeof $osdkMetadata;
|
|
308
|
-
${stringify(definition, {
|
|
309
|
-
osdkMetadata: () => void 0,
|
|
310
|
-
// we are going to reference another object instead
|
|
311
|
-
type: () => void 0,
|
|
312
|
-
apiName: () => void 0,
|
|
313
|
-
links: (_value) => `{
|
|
314
|
-
${stringify(definition.links, {
|
|
315
|
-
"*": (definition2) => `ObjectTypeLinkDefinition<${getObjectDefIdentifier(definition2.targetType, v2)}, ${definition2.multiplicity}>`
|
|
316
|
-
})}
|
|
317
|
-
}`,
|
|
318
|
-
properties: (_value) => `{
|
|
319
|
-
${stringify(definition.properties, {
|
|
320
|
-
"*": (propertyDefinition, _, apiName) => [`${propertyJsdoc(propertyDefinition, {
|
|
321
|
-
apiName
|
|
322
|
-
})}${apiName}`, `PropertyDef<"${propertyDefinition.type}", "${propertyDefinition.nullable ? "nullable" : "non-nullable"}", "${propertyDefinition.multiplicity ? "array" : "single"}">`]
|
|
323
|
-
})}
|
|
324
|
-
}`
|
|
325
|
-
})}
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
`;
|
|
330
|
-
}
|
|
331
|
-
const imports = Array.from(uniqueLinkTargetTypes).filter((type) => type !== definition.apiName).map((type) => `import type { ${getObjectDefIdentifier(type, v2)} } from "./${type}${importExt}";`);
|
|
332
|
-
return `${imports.join("\n")}
|
|
333
|
-
|
|
334
|
-
${v2 ? getV2Types() : getV1Types()}
|
|
335
|
-
|
|
336
|
-
export const ${object.objectType.apiName}: ${objectDefIdentifier} = {
|
|
337
|
-
${v2 ? `osdkMetadata: $osdkMetadata,` : ""}
|
|
338
|
-
${stringify(definition, {
|
|
339
|
-
osdkMetadata: (value) => void 0
|
|
340
|
-
})}
|
|
341
|
-
|
|
342
|
-
};`;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// src/shared/generatePerActionDataFiles.ts
|
|
346
|
-
async function generatePerActionDataFiles(ontology, fs2, outDir, importExt, v2) {
|
|
347
|
-
await fs2.mkdir(outDir, {
|
|
348
|
-
recursive: true
|
|
349
|
-
});
|
|
350
|
-
await Promise.all(Object.values(ontology.actionTypes).map(async (action) => {
|
|
351
|
-
const uniqueApiNames = new Set(extractReferencedObjectsFromAction(action));
|
|
352
|
-
const uniqueApiNamesString = uniqueApiNames.size > 0 ? [...uniqueApiNames].map((apiName) => `"${apiName}"`).join("|") : "never";
|
|
353
|
-
const fullActionDef = deleteUndefineds(wireActionTypeV2ToSdkActionDefinition(action));
|
|
354
|
-
const {
|
|
355
|
-
parameters,
|
|
356
|
-
...actionDefSansParameters
|
|
357
|
-
} = fullActionDef;
|
|
358
|
-
const actionDefIdentifier = `ActionDef$${action.apiName}`;
|
|
359
|
-
const paramsDefIdentifier = `${actionDefIdentifier}$Params`;
|
|
360
|
-
const paramsIdentifier = `${action.apiName}$Params`;
|
|
361
|
-
function createParamsDef() {
|
|
362
|
-
const entries = Object.entries(parameters);
|
|
363
|
-
entries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
364
|
-
if (entries.length === 0) {
|
|
365
|
-
return `// Represents the definition of the parameters for the action
|
|
366
|
-
export type ${paramsDefIdentifier} = Record<string, never>;`;
|
|
367
|
-
}
|
|
368
|
-
return `// Represents the definition of the parameters for the action
|
|
369
|
-
export type ${paramsDefIdentifier} = {
|
|
370
|
-
${entries.map(([key, value]) => {
|
|
371
|
-
return `"${key}": {
|
|
372
|
-
${stringify(value, {
|
|
373
|
-
description: (value2, d) => value2 ? d(value2) : void 0,
|
|
374
|
-
// trick to remove undefineds
|
|
375
|
-
type: (type) => {
|
|
376
|
-
if (typeof type === "string") {
|
|
377
|
-
return JSON.stringify(type);
|
|
378
|
-
} else if (type.type === "object") {
|
|
379
|
-
return `ObjectActionDataType<"${type.object}", ${getObjectDefIdentifier(type.object, v2)}>`;
|
|
380
|
-
} else if (type.type === "objectSet") {
|
|
381
|
-
return `ObjectSetActionDataType<"${type.objectSet}", ${getObjectDefIdentifier(type.objectSet, v2)}>`;
|
|
382
|
-
}
|
|
383
|
-
return void 0;
|
|
384
|
-
}
|
|
385
|
-
})}
|
|
386
|
-
}`;
|
|
387
|
-
}).join(";\n")}
|
|
388
|
-
}`;
|
|
389
|
-
}
|
|
390
|
-
function createV2Types() {
|
|
391
|
-
return `
|
|
392
|
-
|
|
393
|
-
${createParamsDef()}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
// Represents the runtime arguments for the action
|
|
397
|
-
export type ${paramsIdentifier} = NOOP<OsdkActionParameters<${paramsDefIdentifier}>> | NOOP<OsdkActionParameters<${paramsDefIdentifier}>>[];
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
// Represents a fqn of the action
|
|
401
|
-
export interface ${action.apiName} {
|
|
402
|
-
${getDescriptionIfPresent(action.description)}
|
|
403
|
-
<P extends ${paramsIdentifier}, OP extends P extends NOOP<OsdkActionParameters<${paramsDefIdentifier}>>[]? ApplyBatchActionOptions: ApplyActionOptions>(args: P, options?: OP): Promise<ActionReturnTypeForOptions<OP>>;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
// Represents the definition of the action
|
|
408
|
-
export interface ${actionDefIdentifier} extends ActionDefinition<"${action.apiName}", ${uniqueApiNamesString}, ${action.apiName}>, VersionBound<$ExpectedClientVersion> {
|
|
409
|
-
${Object.entries(actionDefSansParameters).sort((a, b) => a[0].localeCompare(b[0])).map(([key, value]) => {
|
|
410
|
-
return `${key}: ${JSON.stringify(value)};`;
|
|
411
|
-
}).join("\n")}
|
|
412
|
-
parameters: ${paramsDefIdentifier};
|
|
413
|
-
osdkMetadata: typeof $osdkMetadata;
|
|
414
|
-
}`;
|
|
415
|
-
}
|
|
416
|
-
function createV2Object() {
|
|
417
|
-
return ` export const ${action.apiName}: ${actionDefIdentifier} =
|
|
418
|
-
{
|
|
419
|
-
${stringify(fullActionDef)},
|
|
420
|
-
osdkMetadata: $osdkMetadata
|
|
421
|
-
}
|
|
422
|
-
`;
|
|
423
|
-
}
|
|
424
|
-
function createV1Object() {
|
|
425
|
-
return ` export const ${action.apiName} = ${JSON.stringify(fullActionDef, null, 2)} satisfies ActionDefinition<"${action.apiName}", ${uniqueApiNamesString}>;`;
|
|
426
|
-
}
|
|
427
|
-
const referencedObjectDefs = /* @__PURE__ */ new Set();
|
|
428
|
-
for (const p of Object.values(action.parameters)) {
|
|
429
|
-
if (p.dataType.type === "object" || p.dataType.type === "objectSet") {
|
|
430
|
-
referencedObjectDefs.add(getObjectDefIdentifier(p.dataType.objectApiName, v2));
|
|
431
|
-
referencedObjectDefs.add(getObjectDefIdentifier(p.dataType.objectTypeApiName, v2));
|
|
432
|
-
}
|
|
433
|
-
if (p.dataType.type === "array" && (p.dataType.subType.type === "object" || p.dataType.subType.type === "objectSet")) {
|
|
434
|
-
referencedObjectDefs.add(getObjectDefIdentifier(p.dataType.subType.objectApiName, v2));
|
|
435
|
-
referencedObjectDefs.add(getObjectDefIdentifier(p.dataType.subType.objectTypeApiName, v2));
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
const importObjects = referencedObjectDefs.size > 0 ? `import type {${[...referencedObjectDefs].join(",")}} from "../objects${importExt}";` : "";
|
|
439
|
-
await fs2.writeFile(path16__namespace.default.join(outDir, `${action.apiName}.ts`), await formatTs(`
|
|
440
|
-
import type { ActionDefinition, ObjectActionDataType, ObjectSetActionDataType, VersionBound} from "@osdk/api";
|
|
441
|
-
import type { ActionSignature, ApplyActionOptions, ApplyBatchActionOptions, OsdkActionParameters,ActionReturnTypeForOptions, NOOP } from '@osdk/client.api';
|
|
442
|
-
import { $osdkMetadata} from "../../OntologyMetadata${importExt}";
|
|
443
|
-
import type { $ExpectedClientVersion } from "../../OntologyMetadata${importExt}";
|
|
444
|
-
${importObjects}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
${v2 ? createV2Types() : ""}
|
|
448
|
-
|
|
449
|
-
${v2 ? createV2Object() : createV1Object()}
|
|
450
|
-
`));
|
|
451
|
-
}));
|
|
452
|
-
await fs2.writeFile(path16__namespace.default.join(outDir, `index.ts`), await formatTs(`
|
|
453
|
-
${Object.values(ontology.actionTypes).map((action) => `export {${action.apiName}} from "./${action.apiName}${importExt}";`).join("\n")}
|
|
454
|
-
${Object.keys(ontology.actionTypes).length === 0 ? "export {};" : ""}
|
|
455
|
-
`));
|
|
456
|
-
}
|
|
457
|
-
function extractReferencedObjectsFromAction(actionType) {
|
|
458
|
-
const referencedObjectsInParameters = Object.values(actionType.parameters).flatMap(({
|
|
459
|
-
dataType
|
|
460
|
-
}) => {
|
|
461
|
-
const objectTypeReference = extractReferencedObjectsFromActionParameter(dataType);
|
|
462
|
-
return objectTypeReference ? [objectTypeReference] : [];
|
|
463
|
-
});
|
|
464
|
-
const referenceObjectsInEdits = actionType.operations.flatMap((value) => {
|
|
465
|
-
switch (value.type) {
|
|
466
|
-
case "createObject":
|
|
467
|
-
return [value.objectTypeApiName];
|
|
468
|
-
case "modifyObject":
|
|
469
|
-
return [value.objectTypeApiName];
|
|
470
|
-
case "deleteObject":
|
|
471
|
-
case "createLink":
|
|
472
|
-
case "deleteLink":
|
|
473
|
-
return [];
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
return [...referenceObjectsInEdits, ...referencedObjectsInParameters];
|
|
477
|
-
}
|
|
478
|
-
function extractReferencedObjectsFromActionParameter(actionParameter) {
|
|
479
|
-
switch (actionParameter.type) {
|
|
480
|
-
case "objectSet":
|
|
481
|
-
case "object":
|
|
482
|
-
return actionParameter.objectTypeApiName;
|
|
483
|
-
case "array":
|
|
484
|
-
return extractReferencedObjectsFromActionParameter(actionParameter.subType);
|
|
485
|
-
case "string":
|
|
486
|
-
case "boolean":
|
|
487
|
-
case "attachment":
|
|
488
|
-
case "date":
|
|
489
|
-
case "double":
|
|
490
|
-
case "integer":
|
|
491
|
-
case "long":
|
|
492
|
-
case "timestamp":
|
|
493
|
-
return void 0;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
// src/shared/sanitizeMetadata.ts
|
|
498
|
-
function sanitizeMetadata(ontology) {
|
|
499
|
-
return {
|
|
500
|
-
...ontology,
|
|
501
|
-
actionTypes: Object.fromEntries(Object.values(ontology.actionTypes).map((actionType) => {
|
|
502
|
-
return [camelize(actionType.apiName), {
|
|
503
|
-
...actionType,
|
|
504
|
-
apiName: camelize(actionType.apiName)
|
|
505
|
-
}];
|
|
506
|
-
}))
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
function camelize(name) {
|
|
510
|
-
return name.replace(/-./g, (segment) => segment[1].toUpperCase());
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
// src/util/verifyOutDir.ts
|
|
514
|
-
async function verifyOutDir(outDir, fs2) {
|
|
515
|
-
try {
|
|
516
|
-
const contents = await fs2.readdir(outDir);
|
|
517
|
-
if (contents.length !== 0) {
|
|
518
|
-
throw new Error(`outDir ${outDir} is not empty, please delete its contents and try again`);
|
|
519
|
-
}
|
|
520
|
-
} catch (e) {
|
|
521
|
-
if (e.code === "ENOENT") ; else {
|
|
522
|
-
throw e;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
320
|
+
// src/v1.1/generateActions.ts
|
|
526
321
|
async function generateActions(ontology, fs2, outDir, importExt = "") {
|
|
527
322
|
const importedObjects = /* @__PURE__ */ new Set();
|
|
528
323
|
let actionSignatures = [];
|
|
@@ -1269,455 +1064,1499 @@ async function generateOntologyIndexFile(fs2, outDir) {
|
|
|
1269
1064
|
export type { ObjectSet } from "@osdk/legacy-client";
|
|
1270
1065
|
`));
|
|
1271
1066
|
}
|
|
1272
|
-
async function generatePerObjectInterfaceAndDataFiles(ontology, fs2, outDir, importExt = "") {
|
|
1273
|
-
await fs2.mkdir(outDir, {
|
|
1274
|
-
recursive: true
|
|
1275
|
-
});
|
|
1276
|
-
await Promise.all(Object.values(ontology.objectTypes).map(async (object) => {
|
|
1277
|
-
object.linkTypes;
|
|
1278
|
-
await fs2.writeFile(path16__namespace.default.join(outDir, `${object.objectType.apiName}.ts`), await formatTs(`
|
|
1279
|
-
import type { ObjectTypeDefinition, ObjectTypeLinkDefinition, PropertyDef } from "@osdk/api";
|
|
1280
|
-
${wireObjectTypeV2ToObjectInterfaceStringV1(object, importExt)}
|
|
1281
1067
|
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
export type { ObjectSet } from "@osdk/legacy-client";
|
|
1288
|
-
|
|
1289
|
-
`));
|
|
1068
|
+
// src/shared/getObjectImports.ts
|
|
1069
|
+
function getObjectImports(objects, curApiName, currentFilePath, v2) {
|
|
1070
|
+
return Array.from(objects).filter((obj) => obj.fullApiName !== curApiName).map((obj) => {
|
|
1071
|
+
return `import type { ${obj.getDefinitionIdentifier(v2)} as ${obj.getImportedDefinitionIdentifier(v2)} } from "${obj.getImportPathRelTo("./" + currentFilePath)}";`;
|
|
1072
|
+
}).join("\n");
|
|
1290
1073
|
}
|
|
1291
1074
|
|
|
1292
|
-
// src/shared/
|
|
1293
|
-
function
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1075
|
+
// src/shared/wireActionTypeV2ToSdkActionDefinition.ts
|
|
1076
|
+
function wireActionTypeV2ToSdkActionDefinition(input) {
|
|
1077
|
+
const modifiedEntityTypes = getModifiedEntityTypes(input);
|
|
1078
|
+
return {
|
|
1079
|
+
type: "action",
|
|
1080
|
+
apiName: input.apiName,
|
|
1081
|
+
parameters: Object.fromEntries(Object.entries(input.parameters).map(([key, value]) => [key, wireActionParameterV2ToSdkParameterDefinition(value)])),
|
|
1082
|
+
displayName: input.displayName,
|
|
1083
|
+
description: input.description,
|
|
1084
|
+
modifiedEntities: createModifiedEntities(modifiedEntityTypes.addedObjects, modifiedEntityTypes.modifiedObjects)
|
|
1085
|
+
};
|
|
1301
1086
|
}
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
case "
|
|
1313
|
-
case "
|
|
1314
|
-
case "
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
case "
|
|
1320
|
-
return
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
nullable: false
|
|
1324
|
-
};
|
|
1087
|
+
function wireActionParameterV2ToSdkParameterDefinition(value) {
|
|
1088
|
+
return {
|
|
1089
|
+
multiplicity: value.dataType.type === "array",
|
|
1090
|
+
type: actionPropertyToSdkPropertyDefinition(value.dataType.type === "array" ? value.dataType.subType : value.dataType),
|
|
1091
|
+
nullable: !value.required,
|
|
1092
|
+
description: value.description
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
function actionPropertyToSdkPropertyDefinition(parameterType) {
|
|
1096
|
+
switch (parameterType.type) {
|
|
1097
|
+
case "string":
|
|
1098
|
+
case "boolean":
|
|
1099
|
+
case "attachment":
|
|
1100
|
+
case "double":
|
|
1101
|
+
case "integer":
|
|
1102
|
+
case "long":
|
|
1103
|
+
case "timestamp":
|
|
1104
|
+
case "marking":
|
|
1105
|
+
return parameterType.type;
|
|
1106
|
+
case "date":
|
|
1107
|
+
return "datetime";
|
|
1325
1108
|
case "objectSet":
|
|
1326
1109
|
return {
|
|
1327
1110
|
type: "objectSet",
|
|
1328
|
-
objectSet:
|
|
1329
|
-
nullable: false
|
|
1330
|
-
};
|
|
1331
|
-
case "array":
|
|
1332
|
-
return {
|
|
1333
|
-
...wireQueryDataTypeToQueryDataTypeDefinition(input.subType),
|
|
1334
|
-
multiplicity: true
|
|
1335
|
-
};
|
|
1336
|
-
case "set":
|
|
1337
|
-
return {
|
|
1338
|
-
type: "set",
|
|
1339
|
-
set: wireQueryDataTypeToQueryDataTypeDefinition(input.subType),
|
|
1340
|
-
nullable: false
|
|
1341
|
-
};
|
|
1342
|
-
case "union":
|
|
1343
|
-
const allowNulls = isNullableQueryDataType(input);
|
|
1344
|
-
if (allowNulls && input.unionTypes.length === 2) {
|
|
1345
|
-
const nonNull = input.unionTypes.find((t) => t.type != null);
|
|
1346
|
-
if (nonNull) {
|
|
1347
|
-
return {
|
|
1348
|
-
...wireQueryDataTypeToQueryDataTypeDefinition(nonNull),
|
|
1349
|
-
nullable: true
|
|
1350
|
-
};
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
return {
|
|
1354
|
-
type: "union",
|
|
1355
|
-
union: input.unionTypes.reduce((acc, t) => {
|
|
1356
|
-
if (t.type === "null") {
|
|
1357
|
-
return acc;
|
|
1358
|
-
}
|
|
1359
|
-
acc.push(wireQueryDataTypeToQueryDataTypeDefinition(t));
|
|
1360
|
-
return acc;
|
|
1361
|
-
}, []),
|
|
1362
|
-
nullable: allowNulls
|
|
1363
|
-
};
|
|
1364
|
-
case "struct":
|
|
1365
|
-
return {
|
|
1366
|
-
type: "struct",
|
|
1367
|
-
struct: Object.fromEntries(input.fields.map((f) => [f.name, wireQueryDataTypeToQueryDataTypeDefinition(f.fieldType)])),
|
|
1368
|
-
nullable: false
|
|
1369
|
-
};
|
|
1370
|
-
case "twoDimensionalAggregation":
|
|
1371
|
-
return {
|
|
1372
|
-
type: "twoDimensionalAggregation",
|
|
1373
|
-
twoDimensionalAggregation: get2DQueryAggregationProps(input),
|
|
1374
|
-
nullable: false
|
|
1111
|
+
objectSet: parameterType.objectTypeApiName
|
|
1375
1112
|
};
|
|
1376
|
-
case "
|
|
1113
|
+
case "object":
|
|
1377
1114
|
return {
|
|
1378
|
-
type: "
|
|
1379
|
-
|
|
1380
|
-
nullable: false
|
|
1115
|
+
type: "object",
|
|
1116
|
+
object: parameterType.objectTypeApiName
|
|
1381
1117
|
};
|
|
1382
|
-
case "
|
|
1383
|
-
|
|
1384
|
-
throw new Error(`Accidentally tried to handle QueryDataType.type ${input.type}`);
|
|
1385
|
-
default:
|
|
1386
|
-
throw new Error(`Unsupported QueryDataType.type ${input.type}`);
|
|
1118
|
+
case "array":
|
|
1119
|
+
return actionPropertyToSdkPropertyDefinition(parameterType.subType);
|
|
1387
1120
|
}
|
|
1388
1121
|
}
|
|
1389
|
-
function
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1122
|
+
function createModifiedEntities(addedObjects, modifiedObjects) {
|
|
1123
|
+
let entities = {};
|
|
1124
|
+
for (const key of addedObjects) {
|
|
1125
|
+
entities[key] = {
|
|
1126
|
+
created: true,
|
|
1127
|
+
modified: false
|
|
1395
1128
|
};
|
|
1396
|
-
} else {
|
|
1397
|
-
if (guardInvalidKeyTypes(input.keyType)) {
|
|
1398
|
-
return {
|
|
1399
|
-
keyType: input.keyType.type,
|
|
1400
|
-
valueType: input.valueType.type
|
|
1401
|
-
};
|
|
1402
|
-
}
|
|
1403
|
-
throw new Error(`Cannot create 2D aggregation with ${input.keyType.type} as its type`);
|
|
1404
1129
|
}
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
};
|
|
1413
|
-
} else {
|
|
1414
|
-
if (guardInvalidKeyTypes(input.keyType)) {
|
|
1415
|
-
return {
|
|
1416
|
-
keyType: input.keyType.type,
|
|
1417
|
-
valueType: get2DQueryAggregationProps(input.valueType)
|
|
1130
|
+
for (const key of modifiedObjects) {
|
|
1131
|
+
if (entities[key]) {
|
|
1132
|
+
entities[key].modified = true;
|
|
1133
|
+
} else {
|
|
1134
|
+
entities[key] = {
|
|
1135
|
+
created: false,
|
|
1136
|
+
modified: true
|
|
1418
1137
|
};
|
|
1419
1138
|
}
|
|
1420
|
-
throw new Error(`Cannot create 3D aggregation with ${input.keyType.type} as its type`);
|
|
1421
1139
|
}
|
|
1422
|
-
|
|
1423
|
-
function guardInvalidKeyTypes(key) {
|
|
1424
|
-
return key.type === "string" || key.type === "boolean";
|
|
1140
|
+
return entities;
|
|
1425
1141
|
}
|
|
1426
1142
|
|
|
1427
|
-
// src/
|
|
1428
|
-
function
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
version: input.version,
|
|
1435
|
-
parameters: Object.fromEntries(Object.entries(input.parameters).map(([name, parameter]) => [name, wireQueryParameterV2ToQueryParameterDefinition(parameter)])),
|
|
1436
|
-
output: wireQueryDataTypeToQueryDataTypeDefinition(input.output)
|
|
1437
|
-
};
|
|
1438
|
-
}
|
|
1439
|
-
function wireQueryTypeV2ToSdkQueryDefinitionNoParams(input) {
|
|
1440
|
-
return {
|
|
1441
|
-
type: "query",
|
|
1442
|
-
apiName: input.apiName,
|
|
1443
|
-
description: input.description,
|
|
1444
|
-
displayName: input.displayName,
|
|
1445
|
-
version: input.version
|
|
1446
|
-
};
|
|
1447
|
-
}
|
|
1448
|
-
function wireQueryParameterV2ToQueryParameterDefinition(parameter) {
|
|
1449
|
-
return {
|
|
1450
|
-
description: parameter.description,
|
|
1451
|
-
...wireQueryDataTypeToQueryDataTypeDefinition(parameter.dataType)
|
|
1452
|
-
};
|
|
1143
|
+
// src/util/stringUnionFrom.ts
|
|
1144
|
+
function stringUnionFrom2(values) {
|
|
1145
|
+
if (values.length === 0) {
|
|
1146
|
+
return "never";
|
|
1147
|
+
} else {
|
|
1148
|
+
return values.map((v) => `"${v}"`).join("|");
|
|
1149
|
+
}
|
|
1453
1150
|
}
|
|
1454
1151
|
|
|
1455
|
-
// src/v1.1/
|
|
1456
|
-
async function
|
|
1152
|
+
// src/v1.1/generatePerActionDataFilesV1.ts
|
|
1153
|
+
async function generatePerActionDataFilesV1({
|
|
1154
|
+
sanitizedOntology: ontology,
|
|
1155
|
+
fs: fs2,
|
|
1156
|
+
outDir: rootOutDir,
|
|
1157
|
+
importExt = "",
|
|
1158
|
+
ontology: enhancedOntology
|
|
1159
|
+
}) {
|
|
1160
|
+
const outDir = path16__namespace.default.join(rootOutDir, "ontology", "actions");
|
|
1457
1161
|
await fs2.mkdir(outDir, {
|
|
1458
1162
|
recursive: true
|
|
1459
1163
|
});
|
|
1460
|
-
await Promise.all(Object.values(
|
|
1461
|
-
const
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1164
|
+
await Promise.all(Object.values(enhancedOntology.actionTypes).map(async (action) => {
|
|
1165
|
+
const currentFilePath = `${path16__namespace.default.join("ontology", "actions", `${action.shortApiName}.ts`)}`;
|
|
1166
|
+
const uniqueApiNamesArray = extractReferencedObjectsFromAction(action.og);
|
|
1167
|
+
const uniqueApiNames = new Set(uniqueApiNamesArray);
|
|
1168
|
+
const uniqueApiNamesString = stringUnionFrom2([...uniqueApiNames]);
|
|
1169
|
+
const fullActionDef = deleteUndefineds(wireActionTypeV2ToSdkActionDefinition(action.og));
|
|
1170
|
+
function createV1Object() {
|
|
1171
|
+
return ` export const ${action.shortApiName} = ${JSON.stringify(fullActionDef, null, 2)} satisfies ActionDefinition<"${action.shortApiName}", ${uniqueApiNamesString}>;`;
|
|
1172
|
+
}
|
|
1173
|
+
const referencedObjectDefs = /* @__PURE__ */ new Set();
|
|
1174
|
+
for (const p of Object.values(action.parameters)) {
|
|
1175
|
+
if (p.dataType.type === "object" || p.dataType.type === "objectSet") {
|
|
1176
|
+
if (p.dataType.objectApiName) {
|
|
1177
|
+
referencedObjectDefs.add(enhancedOntology.requireObjectType(p.dataType.objectApiName));
|
|
1178
|
+
}
|
|
1179
|
+
if (p.dataType.objectTypeApiName) {
|
|
1180
|
+
referencedObjectDefs.add(enhancedOntology.requireObjectType(p.dataType.objectTypeApiName));
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if (p.dataType.type === "array" && (p.dataType.subType.type === "object" || p.dataType.subType.type === "objectSet")) {
|
|
1184
|
+
if (p.dataType.subType.objectApiName) {
|
|
1185
|
+
referencedObjectDefs.add(enhancedOntology.requireObjectType(p.dataType.subType.objectApiName));
|
|
1186
|
+
}
|
|
1187
|
+
if (p.dataType.subType.objectTypeApiName) {
|
|
1188
|
+
referencedObjectDefs.add(enhancedOntology.requireObjectType(p.dataType.subType.objectTypeApiName));
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1481
1191
|
}
|
|
1192
|
+
const imports = getObjectImports(referencedObjectDefs, void 0, currentFilePath, false);
|
|
1193
|
+
await fs2.writeFile(path16__namespace.default.join(rootOutDir, currentFilePath), await formatTs(`
|
|
1194
|
+
import type { ActionDefinition, ObjectActionDataType, ObjectSetActionDataType, VersionBound} from "@osdk/api";
|
|
1195
|
+
import type { ApplyActionOptions, ApplyBatchActionOptions, ActionReturnTypeForOptions, ActionParam } from '@osdk/client.api';
|
|
1196
|
+
import { $osdkMetadata} from "../../OntologyMetadata${importExt}";
|
|
1197
|
+
import type { $ExpectedClientVersion } from "../../OntologyMetadata${importExt}";
|
|
1198
|
+
${imports}
|
|
1199
|
+
|
|
1200
|
+
${createV1Object()}
|
|
1201
|
+
`));
|
|
1482
1202
|
}));
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1203
|
+
const indexFileRelPath = path16__namespace.default.join("ontology", "actions", `index.ts`);
|
|
1204
|
+
await fs2.writeFile(path16__namespace.default.join(rootOutDir, indexFileRelPath), await formatTs(`
|
|
1205
|
+
${Object.values(enhancedOntology.actionTypes).map((action) => {
|
|
1206
|
+
const exportConstLine = `export {${action.shortApiName} } from "${action.getImportPathRelTo(indexFileRelPath)}";`;
|
|
1207
|
+
`export type { ${action.paramsIdentifier} } from "${action.getImportPathRelTo(indexFileRelPath)}";`;
|
|
1208
|
+
return exportConstLine;
|
|
1209
|
+
}).join("\n")}
|
|
1210
|
+
${Object.keys(ontology.actionTypes).length === 0 ? "export {};" : ""}
|
|
1211
|
+
`));
|
|
1487
1212
|
}
|
|
1488
|
-
function
|
|
1489
|
-
const
|
|
1490
|
-
for (const {
|
|
1213
|
+
function extractReferencedObjectsFromAction(actionType) {
|
|
1214
|
+
const referencedObjectsInParameters = Object.values(actionType.parameters).flatMap(({
|
|
1491
1215
|
dataType
|
|
1492
|
-
}
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1216
|
+
}) => {
|
|
1217
|
+
const objectTypeReference = extractReferencedObjectsFromActionParameter(dataType);
|
|
1218
|
+
return objectTypeReference ? [objectTypeReference] : [];
|
|
1219
|
+
});
|
|
1220
|
+
const referenceObjectsInEdits = actionType.operations.flatMap((value) => {
|
|
1221
|
+
switch (value.type) {
|
|
1222
|
+
case "createObject":
|
|
1223
|
+
return [value.objectTypeApiName];
|
|
1224
|
+
case "modifyObject":
|
|
1225
|
+
return [value.objectTypeApiName];
|
|
1226
|
+
case "deleteObject":
|
|
1227
|
+
case "createLink":
|
|
1228
|
+
case "deleteLink":
|
|
1229
|
+
return [];
|
|
1230
|
+
}
|
|
1231
|
+
});
|
|
1232
|
+
return [...referenceObjectsInEdits, ...referencedObjectsInParameters];
|
|
1497
1233
|
}
|
|
1498
|
-
function
|
|
1499
|
-
switch (
|
|
1500
|
-
case "array":
|
|
1501
|
-
case "set":
|
|
1502
|
-
getObjectTypesFromDataType(dataType.subType, types);
|
|
1503
|
-
return;
|
|
1504
|
-
case "object":
|
|
1505
|
-
types.add(dataType.objectTypeApiName);
|
|
1506
|
-
return;
|
|
1234
|
+
function extractReferencedObjectsFromActionParameter(actionParameter) {
|
|
1235
|
+
switch (actionParameter.type) {
|
|
1507
1236
|
case "objectSet":
|
|
1508
|
-
|
|
1509
|
-
return;
|
|
1510
|
-
case "
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
}
|
|
1514
|
-
return;
|
|
1515
|
-
case "union":
|
|
1516
|
-
for (const type of dataType.unionTypes) {
|
|
1517
|
-
getObjectTypesFromDataType(type, types);
|
|
1518
|
-
}
|
|
1519
|
-
return;
|
|
1520
|
-
case "attachment":
|
|
1237
|
+
case "object":
|
|
1238
|
+
return actionParameter.objectTypeApiName;
|
|
1239
|
+
case "array":
|
|
1240
|
+
return extractReferencedObjectsFromActionParameter(actionParameter.subType);
|
|
1241
|
+
case "string":
|
|
1521
1242
|
case "boolean":
|
|
1243
|
+
case "attachment":
|
|
1522
1244
|
case "date":
|
|
1523
1245
|
case "double":
|
|
1524
|
-
case "float":
|
|
1525
1246
|
case "integer":
|
|
1526
1247
|
case "long":
|
|
1527
|
-
case "null":
|
|
1528
|
-
case "string":
|
|
1529
|
-
case "threeDimensionalAggregation":
|
|
1530
1248
|
case "timestamp":
|
|
1531
|
-
|
|
1532
|
-
case "unsupported":
|
|
1533
|
-
return;
|
|
1534
|
-
default:
|
|
1535
|
-
throw new Error(`Cannot find object types from unsupported QueryDataType ${dataType.type}`);
|
|
1249
|
+
return void 0;
|
|
1536
1250
|
}
|
|
1537
1251
|
}
|
|
1538
|
-
|
|
1539
|
-
|
|
1252
|
+
|
|
1253
|
+
// src/util/stringify.ts
|
|
1254
|
+
var defaultCustomizer = (value, defaultValueFormatter, key, defaultKeyFormatter) => {
|
|
1255
|
+
return [defaultKeyFormatter(key), defaultValueFormatter(value)];
|
|
1256
|
+
};
|
|
1257
|
+
function stringify(obj, customizer = {}, separator = ",\n") {
|
|
1258
|
+
const defaultKeyFormatter = (key) => `${JSON.stringify(key)}`;
|
|
1259
|
+
const entries = [];
|
|
1260
|
+
const sortedKeys = Object.keys(obj).sort((a, b) => a.localeCompare(b));
|
|
1261
|
+
for (const key of sortedKeys) {
|
|
1262
|
+
const value = obj[key];
|
|
1263
|
+
const res = (customizer[key] ?? customizer["*"] ?? defaultCustomizer)(value, (value2) => JSON.stringify(value2, null, 2), key, defaultKeyFormatter);
|
|
1264
|
+
if (res) {
|
|
1265
|
+
if (typeof res === "string") {
|
|
1266
|
+
entries.push(`${defaultKeyFormatter(key)}: ${res}`);
|
|
1267
|
+
} else {
|
|
1268
|
+
entries.push(`${res[0]}: ${res[1]}`);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
return entries.join(separator);
|
|
1540
1273
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1274
|
+
|
|
1275
|
+
// src/v1.1/wireObjectTypeV2ToSdkObjectConstV1.ts
|
|
1276
|
+
function wireObjectTypeV2ToSdkObjectConstV1(wireObject, {
|
|
1277
|
+
ontology
|
|
1278
|
+
}, currentFilePath) {
|
|
1279
|
+
const object = ontology.requireObjectType(wireObject.objectType.apiName, true);
|
|
1280
|
+
const uniqueLinkTargetTypes = new Set(wireObject.linkTypes.map((a) => ontology.requireObjectType(a.objectTypeApiName, false)));
|
|
1281
|
+
const definition = deleteUndefineds(generatorConverters.wireObjectTypeFullMetadataToSdkObjectTypeDefinition(object.og, false));
|
|
1282
|
+
const objectDefIdentifier = object.getDefinitionIdentifier(false);
|
|
1283
|
+
function getV1Types() {
|
|
1284
|
+
return `
|
|
1285
|
+
export interface ${objectDefIdentifier} extends ObjectTypeDefinition<"${object.fullApiName}", ${object.uniqueImportName}> {
|
|
1286
|
+
${stringify(definition, {
|
|
1287
|
+
osdkMetadata: () => void 0,
|
|
1288
|
+
// not used in v1
|
|
1289
|
+
links: (_value) => `{
|
|
1290
|
+
${stringify(definition.links, {
|
|
1291
|
+
"*": (definition2) => `ObjectTypeLinkDefinition<${ontology.requireObjectType(definition2.targetType).getImportedDefinitionIdentifier(false)}, ${definition2.multiplicity}>`
|
|
1292
|
+
})}
|
|
1293
|
+
}`
|
|
1294
|
+
})}
|
|
1295
|
+
}
|
|
1544
1296
|
`;
|
|
1297
|
+
}
|
|
1298
|
+
const imports = getObjectImports(uniqueLinkTargetTypes, definition.apiName, currentFilePath, false);
|
|
1299
|
+
return `${imports}${getV1Types()}
|
|
1300
|
+
|
|
1301
|
+
export const ${object.shortApiName}: ${objectDefIdentifier} = {
|
|
1302
|
+
${stringify(definition, {
|
|
1303
|
+
osdkMetadata: (value) => void 0
|
|
1304
|
+
})}
|
|
1305
|
+
|
|
1306
|
+
};`;
|
|
1545
1307
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1308
|
+
|
|
1309
|
+
// src/util/reservedKeywords.ts
|
|
1310
|
+
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"]);
|
|
1311
|
+
function isReservedKeyword(name) {
|
|
1312
|
+
return reservedKeywords.has(name);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
// src/v1.1/wireObjectTypeV2ToV1ObjectInterfaceString.ts
|
|
1316
|
+
function wireObjectTypeV2ToObjectInterfaceStringV1(objectTypeWithLinks, importExt = "") {
|
|
1317
|
+
const uniqueLinkTargets = new Set(objectTypeWithLinks.linkTypes.map((a) => a.objectTypeApiName).filter((a) => a !== objectTypeWithLinks.objectType.apiName));
|
|
1318
|
+
return `import type { OntologyObject, LocalDate, Timestamp, GeoShape, GeoPoint, Attachment, TimeSeries, MultiLink, SingleLink, StringLong } from "@osdk/legacy-client";
|
|
1319
|
+
${Array.from(uniqueLinkTargets).map((linkTarget) => `import type { ${linkTarget} } from "./${linkTarget}${importExt}";`).join("\n")}
|
|
1320
|
+
|
|
1321
|
+
${getDescriptionIfPresent(objectTypeWithLinks.objectType.description)}
|
|
1322
|
+
export interface ${objectTypeWithLinks.objectType.apiName} extends OntologyObject {
|
|
1323
|
+
/** @deprecated please migrate to $apiName instead */
|
|
1324
|
+
readonly __apiName: "${objectTypeWithLinks.objectType.apiName}" & {${objectTypeWithLinks.linkTypes.map((linkType) => {
|
|
1325
|
+
return `/** @deprecated please migrate to pivotTo(${linkType.apiName}) instead */ searchAround${linkType.apiName.charAt(0).toUpperCase() + linkType.apiName.slice(1)}?: never`;
|
|
1326
|
+
})}};
|
|
1327
|
+
/** @deprecated please migrate to $primaryKey instead */
|
|
1328
|
+
readonly __primaryKey: ${wirePropertyTypeV2ToTypeScriptType(objectTypeWithLinks.objectType.properties[objectTypeWithLinks.objectType.primaryKey].dataType)};
|
|
1329
|
+
readonly $apiName: "${objectTypeWithLinks.objectType.apiName}";
|
|
1330
|
+
readonly $primaryKey: ${wirePropertyTypeV2ToTypeScriptType(objectTypeWithLinks.objectType.properties[objectTypeWithLinks.objectType.primaryKey].dataType)};
|
|
1331
|
+
${Object.entries(objectTypeWithLinks.objectType.properties).sort((a, b) => a[0].localeCompare(b[0])).flatMap(([propertyName, propertyDefinition]) => {
|
|
1332
|
+
const propertyType = wirePropertyTypeV2ToTypeScriptType(propertyDefinition.dataType);
|
|
1333
|
+
const entries = [`${getDescriptionIfPresent(propertyDefinition.description, true)}readonly ${propertyName}: ${propertyType} | undefined`];
|
|
1334
|
+
if (isReservedKeyword(propertyName)) {
|
|
1335
|
+
entries.push(`/** @deprecated please migrate to '${propertyName}' instead */
|
|
1336
|
+
readonly ${propertyName}_: ${propertyType} | undefined`);
|
|
1561
1337
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1338
|
+
return entries;
|
|
1339
|
+
}).join(";\n")}
|
|
1340
|
+
${objectTypeWithLinks.linkTypes.flatMap((linkType) => {
|
|
1341
|
+
const entries = [`readonly ${linkType.apiName}: ${linkType.cardinality === "MANY" ? "MultiLink" : "SingleLink"}<${linkType.objectTypeApiName}>`];
|
|
1342
|
+
return entries;
|
|
1343
|
+
}).join(";\n")}
|
|
1344
|
+
}
|
|
1345
|
+
`;
|
|
1346
|
+
}
|
|
1347
|
+
function wirePropertyTypeV2ToTypeScriptType(property) {
|
|
1348
|
+
switch (property.type) {
|
|
1349
|
+
case "string":
|
|
1350
|
+
return "string";
|
|
1351
|
+
case "boolean":
|
|
1352
|
+
return "boolean";
|
|
1353
|
+
case "array":
|
|
1354
|
+
return wirePropertyTypeV2ToTypeScriptType(property.subType) + "[]";
|
|
1355
|
+
case "integer":
|
|
1356
|
+
return "number";
|
|
1357
|
+
case "attachment":
|
|
1358
|
+
return "Attachment";
|
|
1359
|
+
case "byte":
|
|
1360
|
+
return "number";
|
|
1361
|
+
case "date":
|
|
1362
|
+
return "LocalDate";
|
|
1363
|
+
case "decimal":
|
|
1364
|
+
return "string";
|
|
1365
|
+
case "double":
|
|
1366
|
+
return "number";
|
|
1367
|
+
case "float":
|
|
1368
|
+
return "number";
|
|
1369
|
+
case "geopoint":
|
|
1370
|
+
return "GeoPoint";
|
|
1371
|
+
case "geoshape":
|
|
1372
|
+
return "GeoShape";
|
|
1373
|
+
case "long":
|
|
1374
|
+
return "StringLong";
|
|
1375
|
+
case "short":
|
|
1376
|
+
return "number";
|
|
1377
|
+
case "timestamp":
|
|
1378
|
+
return "Timestamp";
|
|
1379
|
+
case "timeseries":
|
|
1380
|
+
return property.itemType.type === "string" ? `TimeSeries<string>` : `TimeSeries<number>`;
|
|
1381
|
+
case "marking":
|
|
1382
|
+
return "string";
|
|
1383
|
+
default:
|
|
1384
|
+
throw new Error(`Unknown property type ${property}`);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
function getDescriptionIfPresent(description, includeNewline) {
|
|
1388
|
+
if (description) {
|
|
1389
|
+
return `/**
|
|
1390
|
+
* ${description}
|
|
1391
|
+
*/${includeNewline ? "\n" : ""}`;
|
|
1568
1392
|
}
|
|
1393
|
+
return "";
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
// src/v1.1/generatePerObjectInterfaceAndDataFiles.ts
|
|
1397
|
+
async function generatePerObjectInterfaceAndDataFiles(ontology, fs2, outDir, importExt = "") {
|
|
1569
1398
|
await fs2.mkdir(outDir, {
|
|
1570
1399
|
recursive: true
|
|
1571
1400
|
});
|
|
1572
|
-
await
|
|
1573
|
-
|
|
1574
|
-
|
|
1401
|
+
await Promise.all(Object.values(ontology.og.objectTypes).map(async (object) => {
|
|
1402
|
+
const relPath = path16__namespace.default.join(".", "ontology", `objects`, `${object.objectType.apiName}.ts`);
|
|
1403
|
+
await fs2.writeFile(path16__namespace.default.join(outDir, `${object.objectType.apiName}.ts`), await formatTs(`
|
|
1404
|
+
import type { ObjectTypeDefinition, ObjectTypeLinkDefinition, PropertyDef } from "@osdk/api";
|
|
1405
|
+
${wireObjectTypeV2ToObjectInterfaceStringV1(object, importExt)}
|
|
1575
1406
|
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
}
|
|
1579
|
-
|
|
1407
|
+
${wireObjectTypeV2ToSdkObjectConstV1(object, {
|
|
1408
|
+
ontology
|
|
1409
|
+
}, relPath)}
|
|
1410
|
+
`));
|
|
1411
|
+
}));
|
|
1412
|
+
await fs2.writeFile(path16__namespace.default.join(outDir, "index.ts"), await formatTs(`
|
|
1413
|
+
${Object.keys(ontology.og.objectTypes).map((apiName) => `export * from "./${apiName}${importExt}";`).join("\n")}
|
|
1414
|
+
export type { ObjectSet } from "@osdk/legacy-client";
|
|
1415
|
+
|
|
1416
|
+
`));
|
|
1580
1417
|
}
|
|
1581
|
-
|
|
1418
|
+
|
|
1419
|
+
// src/shared/getObjectTypesFromQueryDataType.ts
|
|
1420
|
+
function getObjectTypesFromQueryDataType(dataType, types) {
|
|
1582
1421
|
switch (dataType.type) {
|
|
1422
|
+
case "array":
|
|
1423
|
+
case "set":
|
|
1424
|
+
getObjectTypesFromQueryDataType(dataType.subType, types);
|
|
1425
|
+
return;
|
|
1426
|
+
case "object":
|
|
1427
|
+
types.add(dataType.objectTypeApiName);
|
|
1428
|
+
return;
|
|
1429
|
+
case "objectSet":
|
|
1430
|
+
types.add(dataType.objectTypeApiName);
|
|
1431
|
+
return;
|
|
1432
|
+
case "struct":
|
|
1433
|
+
for (const prop of Object.values(dataType.fields)) {
|
|
1434
|
+
getObjectTypesFromQueryDataType(prop.fieldType, types);
|
|
1435
|
+
}
|
|
1436
|
+
return;
|
|
1437
|
+
case "union":
|
|
1438
|
+
for (const type of dataType.unionTypes) {
|
|
1439
|
+
getObjectTypesFromQueryDataType(type, types);
|
|
1440
|
+
}
|
|
1441
|
+
return;
|
|
1442
|
+
case "attachment":
|
|
1583
1443
|
case "boolean":
|
|
1584
|
-
|
|
1444
|
+
case "date":
|
|
1445
|
+
case "double":
|
|
1446
|
+
case "float":
|
|
1447
|
+
case "integer":
|
|
1448
|
+
case "long":
|
|
1449
|
+
case "null":
|
|
1585
1450
|
case "string":
|
|
1586
|
-
|
|
1451
|
+
case "threeDimensionalAggregation":
|
|
1452
|
+
case "timestamp":
|
|
1453
|
+
case "twoDimensionalAggregation":
|
|
1454
|
+
case "unsupported":
|
|
1455
|
+
return;
|
|
1456
|
+
default:
|
|
1457
|
+
throw new Error(`Cannot find object types from unsupported QueryDataType ${dataType.type}`);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
// src/shared/getObjectTypeApiNamesFromQuery.ts
|
|
1462
|
+
function getObjectTypeApiNamesFromQuery(query) {
|
|
1463
|
+
const types = /* @__PURE__ */ new Set();
|
|
1464
|
+
for (const {
|
|
1465
|
+
dataType
|
|
1466
|
+
} of Object.values(query.parameters)) {
|
|
1467
|
+
getObjectTypesFromQueryDataType(dataType, types);
|
|
1468
|
+
}
|
|
1469
|
+
getObjectTypesFromQueryDataType(query.output, types);
|
|
1470
|
+
return Array.from(types);
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
// src/shared/isNullableQueryDataType.ts
|
|
1474
|
+
function isNullableQueryDataType(input) {
|
|
1475
|
+
if (input.type === "null") {
|
|
1476
|
+
return true;
|
|
1477
|
+
}
|
|
1478
|
+
if (input.type === "union") {
|
|
1479
|
+
return input.unionTypes.some((t) => isNullableQueryDataType(t));
|
|
1480
|
+
}
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
// src/shared/wireQueryDataTypeToQueryDataTypeDefinition.ts
|
|
1485
|
+
function wireQueryDataTypeToQueryDataTypeDefinition(input) {
|
|
1486
|
+
switch (input.type) {
|
|
1487
|
+
case "double":
|
|
1488
|
+
case "float":
|
|
1489
|
+
case "integer":
|
|
1490
|
+
case "long":
|
|
1491
|
+
case "attachment":
|
|
1492
|
+
case "boolean":
|
|
1493
|
+
case "date":
|
|
1494
|
+
case "string":
|
|
1495
|
+
case "timestamp":
|
|
1496
|
+
return {
|
|
1497
|
+
type: input.type,
|
|
1498
|
+
nullable: false
|
|
1499
|
+
};
|
|
1500
|
+
case "object":
|
|
1501
|
+
return {
|
|
1502
|
+
type: "object",
|
|
1503
|
+
object: input.objectTypeApiName,
|
|
1504
|
+
nullable: false
|
|
1505
|
+
};
|
|
1506
|
+
case "objectSet":
|
|
1507
|
+
return {
|
|
1508
|
+
type: "objectSet",
|
|
1509
|
+
objectSet: input.objectTypeApiName,
|
|
1510
|
+
nullable: false
|
|
1511
|
+
};
|
|
1512
|
+
case "array":
|
|
1513
|
+
return {
|
|
1514
|
+
...wireQueryDataTypeToQueryDataTypeDefinition(input.subType),
|
|
1515
|
+
multiplicity: true
|
|
1516
|
+
};
|
|
1517
|
+
case "set":
|
|
1518
|
+
return {
|
|
1519
|
+
type: "set",
|
|
1520
|
+
set: wireQueryDataTypeToQueryDataTypeDefinition(input.subType),
|
|
1521
|
+
nullable: false
|
|
1522
|
+
};
|
|
1523
|
+
case "union":
|
|
1524
|
+
const allowNulls = isNullableQueryDataType(input);
|
|
1525
|
+
if (allowNulls && input.unionTypes.length === 2) {
|
|
1526
|
+
const nonNull = input.unionTypes.find((t) => t.type != null);
|
|
1527
|
+
if (nonNull) {
|
|
1528
|
+
return {
|
|
1529
|
+
...wireQueryDataTypeToQueryDataTypeDefinition(nonNull),
|
|
1530
|
+
nullable: true
|
|
1531
|
+
};
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
return {
|
|
1535
|
+
type: "union",
|
|
1536
|
+
union: input.unionTypes.reduce((acc, t) => {
|
|
1537
|
+
if (t.type === "null") {
|
|
1538
|
+
return acc;
|
|
1539
|
+
}
|
|
1540
|
+
acc.push(wireQueryDataTypeToQueryDataTypeDefinition(t));
|
|
1541
|
+
return acc;
|
|
1542
|
+
}, []),
|
|
1543
|
+
nullable: allowNulls
|
|
1544
|
+
};
|
|
1545
|
+
case "struct":
|
|
1546
|
+
return {
|
|
1547
|
+
type: "struct",
|
|
1548
|
+
struct: Object.fromEntries(input.fields.map((f) => [f.name, wireQueryDataTypeToQueryDataTypeDefinition(f.fieldType)])),
|
|
1549
|
+
nullable: false
|
|
1550
|
+
};
|
|
1551
|
+
case "twoDimensionalAggregation":
|
|
1552
|
+
return {
|
|
1553
|
+
type: "twoDimensionalAggregation",
|
|
1554
|
+
twoDimensionalAggregation: get2DQueryAggregationProps(input),
|
|
1555
|
+
nullable: false
|
|
1556
|
+
};
|
|
1557
|
+
case "threeDimensionalAggregation":
|
|
1558
|
+
return {
|
|
1559
|
+
type: "threeDimensionalAggregation",
|
|
1560
|
+
threeDimensionalAggregation: get3DQueryAggregationProps(input),
|
|
1561
|
+
nullable: false
|
|
1562
|
+
};
|
|
1563
|
+
case "null":
|
|
1564
|
+
case "unsupported":
|
|
1565
|
+
throw new Error(`Accidentally tried to handle QueryDataType.type ${input.type}`);
|
|
1566
|
+
default:
|
|
1567
|
+
throw new Error(`Unsupported QueryDataType.type ${input.type}`);
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
function get2DQueryAggregationProps(input) {
|
|
1571
|
+
if (input.keyType.type === "range") {
|
|
1572
|
+
return {
|
|
1573
|
+
keyType: input.keyType.type,
|
|
1574
|
+
keySubtype: input.keyType.subType.type,
|
|
1575
|
+
valueType: input.valueType.type
|
|
1576
|
+
};
|
|
1577
|
+
} else {
|
|
1578
|
+
if (guardInvalidKeyTypes(input.keyType)) {
|
|
1579
|
+
return {
|
|
1580
|
+
keyType: input.keyType.type,
|
|
1581
|
+
valueType: input.valueType.type
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
throw new Error(`Cannot create 2D aggregation with ${input.keyType.type} as its type`);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
function get3DQueryAggregationProps(input) {
|
|
1588
|
+
if (input.keyType.type === "range") {
|
|
1589
|
+
return {
|
|
1590
|
+
keyType: input.keyType.type,
|
|
1591
|
+
keySubtype: input.keyType.subType.type,
|
|
1592
|
+
valueType: get2DQueryAggregationProps(input.valueType)
|
|
1593
|
+
};
|
|
1594
|
+
} else {
|
|
1595
|
+
if (guardInvalidKeyTypes(input.keyType)) {
|
|
1596
|
+
return {
|
|
1597
|
+
keyType: input.keyType.type,
|
|
1598
|
+
valueType: get2DQueryAggregationProps(input.valueType)
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
throw new Error(`Cannot create 3D aggregation with ${input.keyType.type} as its type`);
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
function guardInvalidKeyTypes(key) {
|
|
1605
|
+
return key.type === "string" || key.type === "boolean";
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
// src/shared/wireQueryTypeV2ToSdkQueryDefinition.ts
|
|
1609
|
+
function wireQueryTypeV2ToSdkQueryDefinition(input) {
|
|
1610
|
+
return {
|
|
1611
|
+
type: "query",
|
|
1612
|
+
apiName: input.apiName,
|
|
1613
|
+
description: input.description,
|
|
1614
|
+
displayName: input.displayName,
|
|
1615
|
+
version: input.version,
|
|
1616
|
+
parameters: Object.fromEntries(Object.entries(input.parameters).map(([name, parameter]) => [name, wireQueryParameterV2ToQueryParameterDefinition(parameter)])),
|
|
1617
|
+
output: wireQueryDataTypeToQueryDataTypeDefinition(input.output)
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
function wireQueryTypeV2ToSdkQueryDefinitionNoParams(input) {
|
|
1621
|
+
return {
|
|
1622
|
+
type: "query",
|
|
1623
|
+
apiName: input.apiName,
|
|
1624
|
+
description: input.description,
|
|
1625
|
+
displayName: input.displayName,
|
|
1626
|
+
version: input.version
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1629
|
+
function wireQueryParameterV2ToQueryParameterDefinition(parameter) {
|
|
1630
|
+
return {
|
|
1631
|
+
description: parameter.description,
|
|
1632
|
+
...wireQueryDataTypeToQueryDataTypeDefinition(parameter.dataType)
|
|
1633
|
+
};
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
// src/v1.1/generatePerQueryDataFiles.ts
|
|
1637
|
+
async function generatePerQueryDataFiles({
|
|
1638
|
+
fs: fs2,
|
|
1639
|
+
outDir: rootOutDir,
|
|
1640
|
+
ontology
|
|
1641
|
+
}, v2) {
|
|
1642
|
+
const relOutDir = path16__namespace.default.join(".", "ontology", "queries");
|
|
1643
|
+
const outDir = path16__namespace.default.join(rootOutDir, "ontology", "queries");
|
|
1644
|
+
await fs2.mkdir(outDir, {
|
|
1645
|
+
recursive: true
|
|
1646
|
+
});
|
|
1647
|
+
await Promise.all(Object.values(ontology.queryTypes).map(async (query) => {
|
|
1648
|
+
await generateV1QueryFile(fs2, outDir, query);
|
|
1649
|
+
}));
|
|
1650
|
+
await fs2.writeFile(path16__namespace.default.join(outDir, "index.ts"), await formatTs(`
|
|
1651
|
+
${Object.values(ontology.queryTypes).map((query) => `export * from "${query.getImportPathRelTo(path16__namespace.default.join(relOutDir, "index.ts"))}";`).join("\n")}
|
|
1652
|
+
${Object.keys(ontology.queryTypes).length === 0 ? "export {};" : ""}
|
|
1653
|
+
`));
|
|
1654
|
+
}
|
|
1655
|
+
async function generateV1QueryFile(fs2, outDir, query) {
|
|
1656
|
+
const objectTypes = getObjectTypeApiNamesFromQuery(query);
|
|
1657
|
+
await fs2.writeFile(path16__namespace.default.join(outDir, `${query.shortApiName}.ts`), await formatTs(`
|
|
1658
|
+
import { QueryDefinition } from "@osdk/api";
|
|
1659
|
+
|
|
1660
|
+
export const ${query.shortApiName} = ${JSON.stringify(wireQueryTypeV2ToSdkQueryDefinition(query.og))} ${getQueryDefSatisfies(query.fullApiName, objectTypes)}`));
|
|
1661
|
+
}
|
|
1662
|
+
function getQueryDefSatisfies(apiName, objectTypes) {
|
|
1663
|
+
return `satisfies QueryDefinition<"${apiName}", ${objectTypes.length > 0 ? objectTypes.map((apiNameObj) => `"${apiNameObj}"`).join("|") : "never"}>;`;
|
|
1664
|
+
}
|
|
1665
|
+
async function generateQueries(ontology, fs2, outDir, importExt = "") {
|
|
1666
|
+
const importedObjects = /* @__PURE__ */ new Set();
|
|
1667
|
+
const signatures = [];
|
|
1668
|
+
for (const query of Object.values(ontology.queryTypes)) {
|
|
1669
|
+
const jsDocBlock = ["/**"];
|
|
1670
|
+
if (query.description) {
|
|
1671
|
+
jsDocBlock.push(`* ${query.description}`);
|
|
1672
|
+
}
|
|
1673
|
+
const outputType = handleQueryDataType(query.output, importedObjects, true);
|
|
1674
|
+
const paramEntries = [];
|
|
1675
|
+
for (const [name, parameter] of Object.entries(query.parameters)) {
|
|
1676
|
+
const nullable = isNullableQueryDataType(parameter.dataType);
|
|
1677
|
+
const type = handleQueryDataType(parameter.dataType, importedObjects, false);
|
|
1678
|
+
paramEntries.push(`"${name}"${nullable ? "?" : ""}: ${type}`);
|
|
1679
|
+
jsDocBlock.push(`* @param {${sanitizeDocTypeName(type)}} params.${name}${parameter.description ? ` - ${parameter.description}` : ""}`);
|
|
1680
|
+
}
|
|
1681
|
+
const param = paramEntries.length === 0 ? "" : `params: { ${paramEntries.join("; ")} }`;
|
|
1682
|
+
jsDocBlock.push(`* @returns ${sanitizeDocTypeName(outputType)}`, "*/");
|
|
1683
|
+
signatures.push(`
|
|
1684
|
+
${jsDocBlock.join("\n")}
|
|
1685
|
+
${query.apiName}(${param}): Promise<Result<QueryResponse<${outputType}>, QueryError>>;
|
|
1686
|
+
`);
|
|
1687
|
+
}
|
|
1688
|
+
await fs2.mkdir(outDir, {
|
|
1689
|
+
recursive: true
|
|
1690
|
+
});
|
|
1691
|
+
await fs2.writeFile(path16__namespace.default.join(outDir, "Queries.ts"), await formatTs(`
|
|
1692
|
+
import type { QueryResponse, QueryError, Result, Timestamp, LocalDate, Range, Attachment, ObjectSet, TwoDimensionalAggregation, ThreeDimensionalAggregation } from "@osdk/legacy-client";
|
|
1693
|
+
${Array.from(importedObjects).map((importedObject) => `import type { ${importedObject} } from "../objects/${importedObject}${importExt}";`).join("\n")}
|
|
1694
|
+
|
|
1695
|
+
export interface Queries {
|
|
1696
|
+
${signatures.join("\n")}
|
|
1697
|
+
}
|
|
1698
|
+
`));
|
|
1699
|
+
}
|
|
1700
|
+
function handleQueryDataType(dataType, importedObjects, isReturnValue) {
|
|
1701
|
+
switch (dataType.type) {
|
|
1702
|
+
case "boolean":
|
|
1703
|
+
return "boolean";
|
|
1704
|
+
case "string":
|
|
1705
|
+
return "string";
|
|
1706
|
+
case "double":
|
|
1707
|
+
case "float":
|
|
1708
|
+
case "integer":
|
|
1709
|
+
return "number";
|
|
1710
|
+
case "long":
|
|
1711
|
+
return isReturnValue ? "string" : "string | number";
|
|
1712
|
+
case "date":
|
|
1713
|
+
return "LocalDate";
|
|
1714
|
+
case "timestamp":
|
|
1715
|
+
return "Timestamp";
|
|
1716
|
+
case "attachment":
|
|
1717
|
+
return "Attachment";
|
|
1718
|
+
case "array":
|
|
1719
|
+
return `Array<${handleQueryDataType(dataType.subType, importedObjects, isReturnValue)}>`;
|
|
1720
|
+
case "object": {
|
|
1721
|
+
const objectType = dataType.objectTypeApiName;
|
|
1722
|
+
importedObjects.add(objectType);
|
|
1723
|
+
return isReturnValue ? objectType : `${objectType} | ${objectType}["__primaryKey"]`;
|
|
1724
|
+
}
|
|
1725
|
+
case "objectSet": {
|
|
1726
|
+
const objectType = dataType.objectTypeApiName;
|
|
1727
|
+
importedObjects.add(objectType);
|
|
1728
|
+
return `ObjectSet<${objectType}>`;
|
|
1729
|
+
}
|
|
1730
|
+
case "set":
|
|
1731
|
+
return `Set<${handleQueryDataType(dataType.subType, importedObjects, isReturnValue)}>`;
|
|
1732
|
+
case "struct":
|
|
1733
|
+
const properties = dataType.fields.map((field) => {
|
|
1734
|
+
const isNullable = isNullableQueryDataType(field.fieldType);
|
|
1735
|
+
return `${field.name}${isNullable ? "?" : ""}: ${handleQueryDataType(field.fieldType, importedObjects, isReturnValue)}`;
|
|
1736
|
+
});
|
|
1737
|
+
return `{ ${properties.join(",\n")} }`;
|
|
1738
|
+
case "union":
|
|
1739
|
+
return dataType.unionTypes.map((type) => handleQueryDataType(type, importedObjects, isReturnValue)).filter((type) => type !== "null").join("|");
|
|
1740
|
+
case "twoDimensionalAggregation":
|
|
1741
|
+
dataType.valueType;
|
|
1742
|
+
return `TwoDimensionalAggregation<
|
|
1743
|
+
${aggregationKeyToTypescriptType(dataType.keyType)},
|
|
1744
|
+
${aggregationValueToTypescriptType(dataType.valueType)}
|
|
1745
|
+
>`;
|
|
1746
|
+
case "threeDimensionalAggregation":
|
|
1747
|
+
return `ThreeDimensionalAggregation<
|
|
1748
|
+
${aggregationKeyToTypescriptType(dataType.keyType)},
|
|
1749
|
+
${aggregationKeyToTypescriptType(dataType.valueType.keyType)},
|
|
1750
|
+
${aggregationValueToTypescriptType(dataType.valueType.valueType)}
|
|
1751
|
+
>`;
|
|
1752
|
+
case "null":
|
|
1753
|
+
return "null";
|
|
1754
|
+
case "unsupported":
|
|
1755
|
+
throw new Error("Cannot generate queries for unsupported type");
|
|
1756
|
+
default:
|
|
1757
|
+
throw new Error(`Cannot generate queries for type ${dataType.type}`);
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
function aggregationKeyToTypescriptType(keyType) {
|
|
1761
|
+
switch (keyType.type) {
|
|
1762
|
+
case "boolean":
|
|
1763
|
+
return "boolean";
|
|
1764
|
+
case "double":
|
|
1765
|
+
case "integer":
|
|
1766
|
+
return "number";
|
|
1767
|
+
case "string":
|
|
1768
|
+
return "string";
|
|
1769
|
+
case "date":
|
|
1770
|
+
return "LocalDate";
|
|
1771
|
+
case "timestamp":
|
|
1772
|
+
return "Timestamp";
|
|
1773
|
+
case "range":
|
|
1774
|
+
return `Range<${aggregationRangeToTypescriptType(keyType.subType)}>`;
|
|
1775
|
+
default:
|
|
1776
|
+
throw new Error(`Unknown TwoDimensionalAggregation keyType ${keyType.type}`);
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
function aggregationRangeToTypescriptType(subType) {
|
|
1780
|
+
switch (subType.type) {
|
|
1781
|
+
case "date":
|
|
1782
|
+
return "LocalDate";
|
|
1783
|
+
case "double":
|
|
1784
|
+
case "integer":
|
|
1785
|
+
return "number";
|
|
1786
|
+
case "timestamp":
|
|
1787
|
+
return "Timestamp";
|
|
1788
|
+
default:
|
|
1789
|
+
throw new Error(`Unsupported QueryAggregationRangeSubType ${subType.type}`);
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
function aggregationValueToTypescriptType(valueType) {
|
|
1793
|
+
switch (valueType.type) {
|
|
1794
|
+
case "date":
|
|
1795
|
+
return "LocalDate";
|
|
1796
|
+
case "double":
|
|
1797
|
+
return "number";
|
|
1798
|
+
case "timestamp":
|
|
1799
|
+
return "Timestamp";
|
|
1800
|
+
default:
|
|
1801
|
+
throw new Error(`Unsupported QueryAggregationValueType ${valueType.type}`);
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
function sanitizeDocTypeName(type) {
|
|
1805
|
+
return type.replace(/\s/g, "");
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
// src/v1.1/generateClientSdkVersionOneDotOne.ts
|
|
1809
|
+
async function generateClientSdkVersionOneDotOne(ontology, userAgent, fs2, outDir, packageType = "commonjs") {
|
|
1810
|
+
const importExt = packageType === "module" ? ".js" : "";
|
|
1811
|
+
const objectsDir = path16__namespace.join(outDir, "ontology", "objects");
|
|
1812
|
+
const actionsDir = path16__namespace.join(outDir, "ontology", "actions");
|
|
1813
|
+
const queriesDir = path16__namespace.join(outDir, "ontology", "queries");
|
|
1814
|
+
await verifyOutDir(outDir, fs2);
|
|
1815
|
+
await fs2.mkdir(outDir, {
|
|
1816
|
+
recursive: true
|
|
1817
|
+
});
|
|
1818
|
+
const sanitizedOntology = sanitizeMetadata(ontology);
|
|
1819
|
+
const enhancedOntology = enhanceOntology(sanitizedOntology, void 0, /* @__PURE__ */ new Map(), importExt);
|
|
1820
|
+
await generateFoundryClientFile(fs2, outDir, importExt);
|
|
1821
|
+
await generateMetadataFile(sanitizedOntology, userAgent, fs2, outDir, importExt);
|
|
1822
|
+
await generateOntologyIndexFile(fs2, path16__namespace.join(outDir, "ontology"));
|
|
1823
|
+
await generateObjectsInterfaceFile(sanitizedOntology, fs2, objectsDir, importExt);
|
|
1824
|
+
await generateObjectsInterfaceSupportFiles(sanitizedOntology, fs2, path16__namespace.join(objectsDir, "objects-api"), importExt);
|
|
1825
|
+
await generatePerObjectInterfaceAndDataFiles(enhancedOntology, fs2, objectsDir, importExt);
|
|
1826
|
+
const common = {
|
|
1827
|
+
sanitizedOntology,
|
|
1828
|
+
fs: fs2,
|
|
1829
|
+
outDir,
|
|
1830
|
+
ontology: enhancedOntology
|
|
1831
|
+
};
|
|
1832
|
+
await generateActions(sanitizedOntology, fs2, actionsDir, importExt);
|
|
1833
|
+
await generateBatchActions(sanitizedOntology, fs2, actionsDir, importExt);
|
|
1834
|
+
await generateBulkActions(sanitizedOntology, fs2, actionsDir, importExt);
|
|
1835
|
+
await generatePerActionDataFilesV1(common);
|
|
1836
|
+
await generateQueries(sanitizedOntology, fs2, queriesDir, importExt);
|
|
1837
|
+
await generatePerQueryDataFiles(common);
|
|
1838
|
+
await generateIndexFile(fs2, outDir, importExt);
|
|
1839
|
+
await generateBackCompatDeprecatedExports(fs2, outDir, importExt);
|
|
1840
|
+
}
|
|
1841
|
+
var ExpectedOsdkVersion = "0.22.0";
|
|
1842
|
+
async function generateOntologyMetadataFile({
|
|
1843
|
+
fs: fs2,
|
|
1844
|
+
outDir,
|
|
1845
|
+
ontology,
|
|
1846
|
+
ontologyApiNamespace
|
|
1847
|
+
}, userAgent) {
|
|
1848
|
+
fs2.writeFile(path16__namespace.default.join(outDir, "OntologyMetadata.ts"), await formatTs(`
|
|
1849
|
+
export type $ExpectedClientVersion = "${ExpectedOsdkVersion}";
|
|
1850
|
+
export const $osdkMetadata = { extraUserAgent: "${userAgent}" };
|
|
1851
|
+
${ontologyApiNamespace == null ? `
|
|
1852
|
+
export const $ontologyRid = "${ontology.ontology.rid}";
|
|
1853
|
+
` : ""}
|
|
1854
|
+
`));
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
// src/shared/propertyJsdoc.ts
|
|
1858
|
+
function propertyJsdoc(property, {
|
|
1859
|
+
isInherited,
|
|
1860
|
+
apiName
|
|
1861
|
+
}) {
|
|
1862
|
+
let ret = `/**
|
|
1863
|
+
`;
|
|
1864
|
+
const renderDisplayName = property.displayName && property.displayName !== apiName;
|
|
1865
|
+
if (isInherited || renderDisplayName || property.description) {
|
|
1866
|
+
if (isInherited) {
|
|
1867
|
+
ret += ` * (inherited from parent)
|
|
1868
|
+
`;
|
|
1869
|
+
}
|
|
1870
|
+
if (renderDisplayName) {
|
|
1871
|
+
ret += ` * display name: '${property.displayName}'${property.description ? "," : ""}
|
|
1872
|
+
`;
|
|
1873
|
+
}
|
|
1874
|
+
if (property.description) {
|
|
1875
|
+
ret += ` * description: ${property.description}
|
|
1876
|
+
`;
|
|
1877
|
+
}
|
|
1878
|
+
} else {
|
|
1879
|
+
ret += ` * (no ontology metadata)
|
|
1880
|
+
`;
|
|
1881
|
+
}
|
|
1882
|
+
ret += ` */
|
|
1883
|
+
`;
|
|
1884
|
+
return ret;
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
// src/v2.0/wireObjectTypeV2ToSdkObjectConstV2.ts
|
|
1888
|
+
function getObjectDefIdentifier(name, v2) {
|
|
1889
|
+
return v2 ? name : `${name}Def`;
|
|
1890
|
+
}
|
|
1891
|
+
function wireObjectTypeV2ToSdkObjectConstV2(wireObject, {
|
|
1892
|
+
ontology
|
|
1893
|
+
}, currentFilePath) {
|
|
1894
|
+
const object = ontology.requireObjectType(wireObject.objectType.apiName, true);
|
|
1895
|
+
const uniqueLinkTargetTypes = new Set(wireObject.linkTypes.map((a) => ontology.requireObjectType(a.objectTypeApiName, false)));
|
|
1896
|
+
const definition = deleteUndefineds(generatorConverters.wireObjectTypeFullMetadataToSdkObjectTypeDefinition(object.og, true));
|
|
1897
|
+
const objectDefIdentifier = object.getDefinitionIdentifier(true);
|
|
1898
|
+
const objectSetIdentifier = `${object.shortApiName}.ObjectSet`;
|
|
1899
|
+
const propertyKeysIdentifier = `${object.shortApiName}.PropertyKeys`;
|
|
1900
|
+
const osdkObjectPropsIdentifier = `${object.shortApiName}.Props`;
|
|
1901
|
+
const osdkObjectStrictPropsIdentifier = `${object.shortApiName}.StrictProps`;
|
|
1902
|
+
const osdkObjectLinksIdentifier = `${object.shortApiName}.Links`;
|
|
1903
|
+
const osdkObjectIdentifier = `${object.shortApiName}.OsdkObject`;
|
|
1904
|
+
const identifiers = {
|
|
1905
|
+
objectDefIdentifier: `${object.shortApiName}.Definition`,
|
|
1906
|
+
osdkObjectLinksIdentifier,
|
|
1907
|
+
osdkObjectPropsIdentifier,
|
|
1908
|
+
osdkObjectStrictPropsIdentifier,
|
|
1909
|
+
objectSetIdentifier,
|
|
1910
|
+
osdkObjectIdentifier,
|
|
1911
|
+
propertyKeysIdentifier
|
|
1912
|
+
};
|
|
1913
|
+
function getV2Types() {
|
|
1914
|
+
return `import type {
|
|
1915
|
+
AggregateOpts as $AggregateOpts,
|
|
1916
|
+
AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy as $AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy,
|
|
1917
|
+
AggregationsResults as $AggregationsResults,
|
|
1918
|
+
Augments as $Augments,
|
|
1919
|
+
ConvertProps as $ConvertProps,
|
|
1920
|
+
DefaultToFalse as $DefaultToFalse,
|
|
1921
|
+
FetchPageArgs as $FetchPageArgs,
|
|
1922
|
+
FetchPageResult as $FetchPageResult,
|
|
1923
|
+
LinkedType as $LinkedType,
|
|
1924
|
+
LinkNames as $LinkNames,
|
|
1925
|
+
NullabilityAdherence as $NullabilityAdherence,
|
|
1926
|
+
NullabilityAdherenceDefault as $NullabilityAdherenceDefault,
|
|
1927
|
+
ObjectSet as $ObjectSet,
|
|
1928
|
+
Osdk as $Osdk,
|
|
1929
|
+
OsdkObject as $OsdkObject,
|
|
1930
|
+
OsdkObjectLinksEntry as $OsdkObjectLinksEntry,
|
|
1931
|
+
OsdkObjectLinksObject as $OsdkObjectLinksObject,
|
|
1932
|
+
OsdkObjectPropertyType as $OsdkObjectPropertyType,
|
|
1933
|
+
PageResult as $PageResult,
|
|
1934
|
+
PropertyValueClientToWire as $PropertyValueClientToWire,
|
|
1935
|
+
PropertyValueWireToClient as $PropType,
|
|
1936
|
+
Result as $Result,
|
|
1937
|
+
SelectArg as $SelectArg,
|
|
1938
|
+
SingleLinkAccessor as $SingleLinkAccessor,
|
|
1939
|
+
SingleLinkAccessor as $SingleLinkAccessor
|
|
1940
|
+
SingleOsdkResult as $SingleOsdkResult,
|
|
1941
|
+
ValidToFrom as $ValidToFrom,
|
|
1942
|
+
WhereClause as $WhereClause,
|
|
1943
|
+
} from "@osdk/client.api";
|
|
1944
|
+
import type * as $clientApi from "@osdk/client.api";
|
|
1945
|
+
import type {
|
|
1946
|
+
ObjectOrInterfacePropertyKeysFrom2 as $ObjectOrInterfacePropertyKeysFrom2,
|
|
1947
|
+
ObjectTypeDefinition as $ObjectTypeDefinition,
|
|
1948
|
+
ObjectTypeLinkDefinition as $ObjectTypeLinkDefinition,
|
|
1949
|
+
} from "@osdk/api";
|
|
1950
|
+
|
|
1951
|
+
export namespace ${object.shortApiName} {
|
|
1952
|
+
|
|
1953
|
+
${createPropertyKeys(object)}
|
|
1954
|
+
|
|
1955
|
+
|
|
1956
|
+
${createLinks(ontology, object, "Links")}
|
|
1957
|
+
|
|
1958
|
+
${createProps(object, "Props", false)}
|
|
1959
|
+
${createProps(object, "StrictProps", true)}
|
|
1960
|
+
|
|
1961
|
+
${createObjectSet(object, identifiers)}
|
|
1962
|
+
|
|
1963
|
+
${createDefinition(object, ontology, "Definition", identifiers)}
|
|
1964
|
+
${createOsdkObject(object, "OsdkObject", identifiers)}
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
|
|
1968
|
+
|
|
1969
|
+
|
|
1970
|
+
/** @deprecated use ${object.shortApiName}.Definition **/
|
|
1971
|
+
export type ${objectDefIdentifier} = ${object.shortApiName}.Definition;
|
|
1972
|
+
|
|
1973
|
+
|
|
1974
|
+
`;
|
|
1975
|
+
}
|
|
1976
|
+
const imports = getObjectImports(uniqueLinkTargetTypes, definition.apiName, currentFilePath, true);
|
|
1977
|
+
return `${imports}${getV2Types()}
|
|
1978
|
+
|
|
1979
|
+
export const ${object.shortApiName}: ${objectDefIdentifier} & $VersionBound<$ExpectedClientVersion>
|
|
1980
|
+
= {
|
|
1981
|
+
osdkMetadata: $osdkMetadata,
|
|
1982
|
+
objectSet: undefined as any,
|
|
1983
|
+
props: undefined as any,
|
|
1984
|
+
strictProps: undefined as any,
|
|
1985
|
+
${stringify(definition, {
|
|
1986
|
+
osdkMetadata: (value) => void 0
|
|
1987
|
+
})}
|
|
1988
|
+
|
|
1989
|
+
};`;
|
|
1990
|
+
}
|
|
1991
|
+
function createOsdkObject(object, identifier, {
|
|
1992
|
+
osdkObjectPropsIdentifier,
|
|
1993
|
+
objectDefIdentifier,
|
|
1994
|
+
osdkObjectStrictPropsIdentifier,
|
|
1995
|
+
osdkObjectLinksIdentifier
|
|
1996
|
+
}) {
|
|
1997
|
+
const definition = object.getCleanedUpDefinition(true);
|
|
1998
|
+
return `
|
|
1999
|
+
export type ${identifier}<
|
|
2000
|
+
OPTIONS extends never | "$notStrict" | "$rid" = never,
|
|
2001
|
+
K extends keyof ${osdkObjectPropsIdentifier}= keyof ${osdkObjectPropsIdentifier},
|
|
2002
|
+
|
|
2003
|
+
>
|
|
2004
|
+
= $Osdk<
|
|
2005
|
+
${objectDefIdentifier},
|
|
2006
|
+
K | OPTIONS
|
|
2007
|
+
> & Pick<
|
|
2008
|
+
[OPTIONS] extends [never]
|
|
2009
|
+
? ${osdkObjectStrictPropsIdentifier} :
|
|
2010
|
+
OPTIONS extends "$notStrict" ? ${osdkObjectPropsIdentifier} : ${osdkObjectStrictPropsIdentifier}
|
|
2011
|
+
, K
|
|
2012
|
+
> & {
|
|
2013
|
+
readonly $link: ${osdkObjectLinksIdentifier};
|
|
2014
|
+
readonly $title: string | undefined; // FIXME
|
|
2015
|
+
readonly $primaryKey: ${"primaryKeyApiName" in definition ? `
|
|
2016
|
+
$OsdkObjectPropertyType<${JSON.stringify(definition.properties[definition.primaryKeyApiName])},${true}>` : "string | number"}
|
|
2017
|
+
;
|
|
2018
|
+
|
|
2019
|
+
readonly $as: <NEW_Q extends $ValidToFrom<${objectDefIdentifier}>>(type: NEW_Q | string) => $Osdk<
|
|
2020
|
+
NEW_Q,
|
|
2021
|
+
$ConvertProps<${objectDefIdentifier}, NEW_Q, K>
|
|
2022
|
+
>;
|
|
2023
|
+
} & $OsdkObject<"${object.fullApiName}">;`;
|
|
2024
|
+
}
|
|
2025
|
+
function createObjectSet(object, {
|
|
2026
|
+
objectDefIdentifier,
|
|
2027
|
+
objectSetIdentifier,
|
|
2028
|
+
propertyKeysIdentifier,
|
|
2029
|
+
osdkObjectIdentifier
|
|
2030
|
+
}) {
|
|
2031
|
+
return `
|
|
2032
|
+
export interface ObjectSet extends
|
|
2033
|
+
$ObjectSet<${objectDefIdentifier},
|
|
2034
|
+
|
|
2035
|
+
${objectSetIdentifier}
|
|
2036
|
+
>
|
|
2037
|
+
{
|
|
2038
|
+
readonly aggregate: <AO extends $AggregateOpts<${objectDefIdentifier}>>(
|
|
2039
|
+
req: $AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy<${objectDefIdentifier}, AO>,
|
|
2040
|
+
) => Promise<$AggregationsResults<${objectDefIdentifier}, AO>>;
|
|
2041
|
+
|
|
2042
|
+
|
|
2043
|
+
readonly pivotTo: <L extends $LinkNames<${objectDefIdentifier}>>(type: L) => $LinkedType<${objectDefIdentifier}, L>["objectSet"];
|
|
2044
|
+
${object instanceof EnhancedObjectType ? `
|
|
2045
|
+
readonly fetchOne: <
|
|
2046
|
+
L extends ${propertyKeysIdentifier},
|
|
2047
|
+
R extends boolean,
|
|
2048
|
+
S extends false | "throw" = $NullabilityAdherenceDefault,
|
|
2049
|
+
>(
|
|
2050
|
+
primaryKey: $PropertyValueClientToWire[${objectDefIdentifier}["primaryKeyType"]],
|
|
2051
|
+
options?: $SelectArg<${objectDefIdentifier}, L, R, S>,
|
|
2052
|
+
) => Promise<
|
|
2053
|
+
${osdkObjectIdentifier}<
|
|
2054
|
+
(S extends false ? "$notStrict" : never) | ($DefaultToFalse<R> extends false? never: "$rid" ),
|
|
2055
|
+
L
|
|
2056
|
+
>>
|
|
2057
|
+
;
|
|
2058
|
+
|
|
2059
|
+
readonly fetchOneWithErrors: <
|
|
2060
|
+
L extends ${propertyKeysIdentifier},
|
|
2061
|
+
R extends boolean,
|
|
2062
|
+
S extends false | "throw" = $NullabilityAdherenceDefault,
|
|
2063
|
+
>(
|
|
2064
|
+
primaryKey: $PropertyValueClientToWire[${objectDefIdentifier}["primaryKeyType"]],
|
|
2065
|
+
options?: $SelectArg<${objectDefIdentifier}, L, R, S>,
|
|
2066
|
+
) => Promise<$Result<
|
|
2067
|
+
${osdkObjectIdentifier}<
|
|
2068
|
+
(S extends false ? "$notStrict" : never) | ($DefaultToFalse<R> extends false?never: "$rid"),
|
|
2069
|
+
L
|
|
2070
|
+
>
|
|
2071
|
+
>>
|
|
2072
|
+
|
|
2073
|
+
;
|
|
2074
|
+
|
|
2075
|
+
` : ""}
|
|
2076
|
+
|
|
2077
|
+
readonly fetchPage: <
|
|
2078
|
+
L extends ${propertyKeysIdentifier},
|
|
2079
|
+
R extends boolean,
|
|
2080
|
+
const A extends $Augments,
|
|
2081
|
+
S extends $NullabilityAdherence = $NullabilityAdherenceDefault,
|
|
2082
|
+
>(
|
|
2083
|
+
args?: $FetchPageArgs<${objectDefIdentifier}, L, R, A, S>,
|
|
2084
|
+
) => Promise<
|
|
2085
|
+
$PageResult<${osdkObjectIdentifier}<
|
|
2086
|
+
(S extends false ? "$notStrict" : never) | ($DefaultToFalse<R> extends false? never: "$rid"),
|
|
2087
|
+
L
|
|
2088
|
+
>>
|
|
2089
|
+
>;
|
|
2090
|
+
|
|
2091
|
+
readonly fetchPageWithErrors: <
|
|
2092
|
+
L extends ${propertyKeysIdentifier},
|
|
2093
|
+
R extends boolean,
|
|
2094
|
+
const A extends $Augments,
|
|
2095
|
+
S extends $NullabilityAdherence = $NullabilityAdherenceDefault,
|
|
2096
|
+
>(
|
|
2097
|
+
args?: $FetchPageArgs<${objectDefIdentifier}, L, R, A, S>,
|
|
2098
|
+
) => Promise<$Result<
|
|
2099
|
+
$PageResult<${osdkObjectIdentifier}<
|
|
2100
|
+
(S extends false ? "$notStrict" : never) | ($DefaultToFalse<R> extends false? never : "$rid"),
|
|
2101
|
+
L>>
|
|
2102
|
+
>>;
|
|
2103
|
+
|
|
2104
|
+
readonly asyncIter: () => AsyncIterableIterator<${osdkObjectIdentifier}>;
|
|
2105
|
+
}
|
|
2106
|
+
`;
|
|
2107
|
+
}
|
|
2108
|
+
function maybeStripNamespace(type, q) {
|
|
2109
|
+
if (type.apiNamespace && q.startsWith(`${type.apiNamespace}.`)) {
|
|
2110
|
+
return q.slice(type.apiNamespace.length + 1);
|
|
2111
|
+
} else {
|
|
2112
|
+
return q;
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
function createProps(type, identifier, strict) {
|
|
2116
|
+
const definition = type.getCleanedUpDefinition(true);
|
|
2117
|
+
return `export interface ${identifier} {
|
|
2118
|
+
${stringify(definition.properties, {
|
|
2119
|
+
"*": (propertyDefinition, _, apiName) => {
|
|
2120
|
+
return [`readonly "${maybeStripNamespace(type, apiName)}"${// after we convert everything over we can do this:
|
|
2121
|
+
// !strict || propertyDefinition.nullable ? "?" : ""
|
|
2122
|
+
""}`, `$PropType[${JSON.stringify(propertyDefinition.type)}]${propertyDefinition.multiplicity ? "[]" : ""}${propertyDefinition.nullable || !strict ? `| undefined` : ""}`];
|
|
2123
|
+
}
|
|
2124
|
+
})}
|
|
2125
|
+
}`;
|
|
2126
|
+
}
|
|
2127
|
+
function createDefinition(object, ontology, identifier, {
|
|
2128
|
+
objectDefIdentifier,
|
|
2129
|
+
objectSetIdentifier,
|
|
2130
|
+
osdkObjectPropsIdentifier,
|
|
2131
|
+
osdkObjectStrictPropsIdentifier
|
|
2132
|
+
}) {
|
|
2133
|
+
const definition = object.getCleanedUpDefinition(true);
|
|
2134
|
+
return `
|
|
2135
|
+
export interface ${identifier} extends ${object instanceof EnhancedObjectType ? `$ObjectTypeDefinition` : `$InterfaceDefinition`}<"${object.fullApiName}", ${objectDefIdentifier}>, $VersionBound<$ExpectedClientVersion> {
|
|
2136
|
+
osdkMetadata: typeof $osdkMetadata;
|
|
2137
|
+
objectSet: ${objectSetIdentifier};
|
|
2138
|
+
props: ${osdkObjectPropsIdentifier};
|
|
2139
|
+
strictProps: ${osdkObjectStrictPropsIdentifier};
|
|
2140
|
+
${stringify(definition, {
|
|
2141
|
+
osdkMetadata: () => void 0,
|
|
2142
|
+
// we are going to reference another object instead
|
|
2143
|
+
type: () => void 0,
|
|
2144
|
+
apiName: () => void 0,
|
|
2145
|
+
links: (_value) => `{
|
|
2146
|
+
${stringify(definition.links, {
|
|
2147
|
+
"*": (definition2) => `$ObjectTypeLinkDefinition<${ontology.requireObjectType(definition2.targetType).getImportedDefinitionIdentifier(true)}, ${definition2.multiplicity}>`
|
|
2148
|
+
})}
|
|
2149
|
+
}`,
|
|
2150
|
+
properties: (_value) => `{
|
|
2151
|
+
${stringify(definition.properties, {
|
|
2152
|
+
"*": (propertyDefinition, _, apiName) => [`${propertyJsdoc(propertyDefinition, {
|
|
2153
|
+
apiName
|
|
2154
|
+
})}"${maybeStripNamespace(object, apiName)}"`, `$PropertyDef<"${propertyDefinition.type}", "${propertyDefinition.nullable ? "nullable" : "non-nullable"}", "${propertyDefinition.multiplicity ? "array" : "single"}">`]
|
|
2155
|
+
})}
|
|
2156
|
+
}`
|
|
2157
|
+
})}
|
|
2158
|
+
}
|
|
2159
|
+
`;
|
|
2160
|
+
}
|
|
2161
|
+
function createLinks(ontology, object, identifier) {
|
|
2162
|
+
const definition = object.getCleanedUpDefinition(true);
|
|
2163
|
+
return `
|
|
2164
|
+
${Object.keys(definition.links).length === 0 ? `export type ${identifier} = never;` : `
|
|
2165
|
+
export interface ${identifier} {
|
|
2166
|
+
${stringify(definition.links, {
|
|
2167
|
+
"*": (definition2, _, key) => {
|
|
2168
|
+
const linkTarget = ontology.requireObjectType(definition2.targetType).getImportedDefinitionIdentifier(true);
|
|
2169
|
+
return [`readonly ${key}`, `${definition2.multiplicity ? `${linkTarget}.ObjectSet` : `$SingleLinkAccessor<${linkTarget}.Definition>`}
|
|
2170
|
+
`];
|
|
2171
|
+
}
|
|
2172
|
+
})}
|
|
2173
|
+
}
|
|
2174
|
+
`}`;
|
|
2175
|
+
}
|
|
2176
|
+
function createPropertyKeys(type) {
|
|
2177
|
+
return `export type PropertyKeys = ${Object.keys(type.getCleanedUpDefinition(true).properties).map((a) => maybeStripNamespace(type, a)).map((a) => `"${a}"`).join("|")};`;
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
// src/v2.0/generatePerActionDataFiles.ts
|
|
2181
|
+
async function generatePerActionDataFiles({
|
|
2182
|
+
sanitizedOntology: ontology,
|
|
2183
|
+
fs: fs2,
|
|
2184
|
+
outDir: rootOutDir,
|
|
2185
|
+
importExt = "",
|
|
2186
|
+
ontology: enhancedOntology
|
|
2187
|
+
}) {
|
|
2188
|
+
const outDir = path16__namespace.default.join(rootOutDir, "ontology", "actions");
|
|
2189
|
+
await fs2.mkdir(outDir, {
|
|
2190
|
+
recursive: true
|
|
2191
|
+
});
|
|
2192
|
+
await Promise.all(Object.values(enhancedOntology.actionTypes).map(async (action) => {
|
|
2193
|
+
const currentFilePath = `${path16__namespace.default.join("ontology", "actions", `${action.shortApiName}.ts`)}`;
|
|
2194
|
+
const uniqueApiNamesArray = extractReferencedObjectsFromAction2(action.og);
|
|
2195
|
+
const uniqueApiNames = new Set(uniqueApiNamesArray);
|
|
2196
|
+
const uniqueApiNamesString = stringUnionFrom2([...uniqueApiNames]);
|
|
2197
|
+
const fullActionDef = deleteUndefineds(wireActionTypeV2ToSdkActionDefinition(action.og));
|
|
2198
|
+
const {
|
|
2199
|
+
parameters,
|
|
2200
|
+
...actionDefSansParameters
|
|
2201
|
+
} = fullActionDef;
|
|
2202
|
+
function createParamsDef() {
|
|
2203
|
+
const entries = Object.entries(parameters);
|
|
2204
|
+
entries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
2205
|
+
if (entries.length === 0) {
|
|
2206
|
+
return `// Represents the definition of the parameters for the action
|
|
2207
|
+
export type ParamsDefinition = Record<string, never>;`;
|
|
2208
|
+
}
|
|
2209
|
+
return `// Represents the definition of the parameters for the action
|
|
2210
|
+
export type ParamsDefinition = {
|
|
2211
|
+
${entries.map(([key, value]) => {
|
|
2212
|
+
return `"${key}": {
|
|
2213
|
+
${stringify(value, {
|
|
2214
|
+
description: (value2, d) => value2 ? d(value2) : void 0,
|
|
2215
|
+
// trick to remove undefineds
|
|
2216
|
+
type: (type) => {
|
|
2217
|
+
if (typeof type === "string") {
|
|
2218
|
+
return JSON.stringify(type);
|
|
2219
|
+
} else if (type.type === "object") {
|
|
2220
|
+
const obj = enhancedOntology.requireObjectType(type.object);
|
|
2221
|
+
return `ObjectActionDataType<"${obj.fullApiName}", ${obj.getImportedDefinitionIdentifier(true)}>`;
|
|
2222
|
+
} else if (type.type === "objectSet") {
|
|
2223
|
+
return `ObjectSetActionDataType<"${type.objectSet}", ${getObjectDefIdentifier(type.objectSet, true)}>`;
|
|
2224
|
+
}
|
|
2225
|
+
return void 0;
|
|
2226
|
+
}
|
|
2227
|
+
})}
|
|
2228
|
+
}`;
|
|
2229
|
+
}).join(";\n")}
|
|
2230
|
+
}`;
|
|
2231
|
+
}
|
|
2232
|
+
function getActionParamType(input) {
|
|
2233
|
+
if (typeof input === "string") {
|
|
2234
|
+
return `ActionParam.PrimitiveType<${JSON.stringify(input)}>`;
|
|
2235
|
+
} else if (input.type === "object") {
|
|
2236
|
+
return `ActionParam.ObjectType<${enhancedOntology.requireObjectType(input.object).getImportedDefinitionIdentifier(true)}>`;
|
|
2237
|
+
} else if (input.type === "objectSet") {
|
|
2238
|
+
return `ActionParam.ObjectSetType<${enhancedOntology.requireObjectType(input.objectSet).getImportedDefinitionIdentifier(true)}>`;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
function createV2Types() {
|
|
2242
|
+
const oldParamsIdentifier = `${action.shortApiName}$Params`;
|
|
2243
|
+
return `
|
|
2244
|
+
|
|
2245
|
+
export namespace ${action.shortApiName}{
|
|
2246
|
+
${createParamsDef()}
|
|
2247
|
+
|
|
2248
|
+
${getDescriptionIfPresent(action.description)}
|
|
2249
|
+
export interface Parameters {
|
|
2250
|
+
${stringify(parameters, {
|
|
2251
|
+
"*": (ogValue, _, ogKey) => {
|
|
2252
|
+
const key = `${getDescriptionIfPresent(ogValue.description)}
|
|
2253
|
+
readonly "${ogKey}"${ogValue.nullable ? "?" : ""}`;
|
|
2254
|
+
const value = ogValue.multiplicity ? `ReadonlyArray<${getActionParamType(ogValue.type)}>` : `${getActionParamType(ogValue.type)}`;
|
|
2255
|
+
return [key, value];
|
|
2256
|
+
}
|
|
2257
|
+
})}
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
|
|
2261
|
+
// Represents the definition of the action
|
|
2262
|
+
export interface Definition extends ActionDefinition<"${action.shortApiName}", ${uniqueApiNamesString}, ${action.shortApiName}>, VersionBound<$ExpectedClientVersion> {
|
|
2263
|
+
${Object.entries(actionDefSansParameters).sort((a, b) => a[0].localeCompare(b[0])).map(([key, value]) => {
|
|
2264
|
+
return `${key}: ${JSON.stringify(value)};`;
|
|
2265
|
+
}).join("\n")}
|
|
2266
|
+
parameters: ${action.definitionParamsIdentifier};
|
|
2267
|
+
osdkMetadata: typeof $osdkMetadata;
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
// Represents a fqn of the action
|
|
2271
|
+
export interface Signature {
|
|
2272
|
+
${getDescriptionIfPresent(action.description)}
|
|
2273
|
+
<P extends ${action.paramsIdentifier} | ReadonlyArray<${action.paramsIdentifier}>, OP extends (P extends ReadonlyArray<${action.paramsIdentifier}> ? ApplyBatchActionOptions: ApplyActionOptions)>(args: P, options?: OP): Promise<ActionReturnTypeForOptions<OP>>;
|
|
2274
|
+
}
|
|
2275
|
+
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
/**
|
|
2279
|
+
* @deprecated Use \`${action.paramsIdentifier}\`
|
|
2280
|
+
*/
|
|
2281
|
+
export type ${oldParamsIdentifier} = ${action.paramsIdentifier} | ReadonlyArray<${action.paramsIdentifier}>;
|
|
2282
|
+
|
|
2283
|
+
/** @deprecated Use \`${action.definitionIdentifier}\` **/
|
|
2284
|
+
export type ${action.shortApiName} = ${action.shortApiName}.Signature;
|
|
2285
|
+
`;
|
|
2286
|
+
}
|
|
2287
|
+
function createV2Object() {
|
|
2288
|
+
return ` export const ${action.shortApiName}: ${action.definitionIdentifier} =
|
|
2289
|
+
{
|
|
2290
|
+
${stringify(fullActionDef)},
|
|
2291
|
+
osdkMetadata: $osdkMetadata
|
|
2292
|
+
}
|
|
2293
|
+
`;
|
|
2294
|
+
}
|
|
2295
|
+
const referencedObjectDefs = /* @__PURE__ */ new Set();
|
|
2296
|
+
for (const p of Object.values(action.parameters)) {
|
|
2297
|
+
if (p.dataType.type === "object" || p.dataType.type === "objectSet") {
|
|
2298
|
+
if (p.dataType.objectApiName) {
|
|
2299
|
+
referencedObjectDefs.add(enhancedOntology.requireObjectType(p.dataType.objectApiName));
|
|
2300
|
+
}
|
|
2301
|
+
if (p.dataType.objectTypeApiName) {
|
|
2302
|
+
referencedObjectDefs.add(enhancedOntology.requireObjectType(p.dataType.objectTypeApiName));
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
if (p.dataType.type === "array" && (p.dataType.subType.type === "object" || p.dataType.subType.type === "objectSet")) {
|
|
2306
|
+
if (p.dataType.subType.objectApiName) {
|
|
2307
|
+
referencedObjectDefs.add(enhancedOntology.requireObjectType(p.dataType.subType.objectApiName));
|
|
2308
|
+
}
|
|
2309
|
+
if (p.dataType.subType.objectTypeApiName) {
|
|
2310
|
+
referencedObjectDefs.add(enhancedOntology.requireObjectType(p.dataType.subType.objectTypeApiName));
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
const imports = getObjectImports(referencedObjectDefs, void 0, currentFilePath, true);
|
|
2315
|
+
await fs2.writeFile(path16__namespace.default.join(rootOutDir, currentFilePath), await formatTs(`
|
|
2316
|
+
import type { ActionDefinition, ObjectActionDataType, ObjectSetActionDataType, VersionBound} from "@osdk/api";
|
|
2317
|
+
import type { ApplyActionOptions, ApplyBatchActionOptions, ActionReturnTypeForOptions, ActionParam } from '@osdk/client.api';
|
|
2318
|
+
import { $osdkMetadata} from "../../OntologyMetadata${importExt}";
|
|
2319
|
+
import type { $ExpectedClientVersion } from "../../OntologyMetadata${importExt}";
|
|
2320
|
+
${imports}
|
|
2321
|
+
|
|
2322
|
+
|
|
2323
|
+
${createV2Types()}
|
|
2324
|
+
|
|
2325
|
+
${createV2Object()}
|
|
2326
|
+
`));
|
|
2327
|
+
}));
|
|
2328
|
+
const indexFileRelPath = path16__namespace.default.join("ontology", "actions.ts");
|
|
2329
|
+
await fs2.writeFile(path16__namespace.default.join(rootOutDir, indexFileRelPath), await formatTs(`
|
|
2330
|
+
${Object.values(enhancedOntology.actionTypes).map((action) => {
|
|
2331
|
+
const exportConstLine = `export {${action.shortApiName} } from "${action.getImportPathRelTo(indexFileRelPath)}";`;
|
|
2332
|
+
return exportConstLine;
|
|
2333
|
+
}).join("\n")}
|
|
2334
|
+
${Object.keys(ontology.actionTypes).length === 0 ? "export {};" : ""}
|
|
2335
|
+
`));
|
|
2336
|
+
}
|
|
2337
|
+
function extractReferencedObjectsFromAction2(actionType) {
|
|
2338
|
+
const referencedObjectsInParameters = Object.values(actionType.parameters).flatMap(({
|
|
2339
|
+
dataType
|
|
2340
|
+
}) => {
|
|
2341
|
+
const objectTypeReference = extractReferencedObjectsFromActionParameter2(dataType);
|
|
2342
|
+
return objectTypeReference ? [objectTypeReference] : [];
|
|
2343
|
+
});
|
|
2344
|
+
const referenceObjectsInEdits = actionType.operations.flatMap((value) => {
|
|
2345
|
+
switch (value.type) {
|
|
2346
|
+
case "createObject":
|
|
2347
|
+
return [value.objectTypeApiName];
|
|
2348
|
+
case "modifyObject":
|
|
2349
|
+
return [value.objectTypeApiName];
|
|
2350
|
+
case "deleteObject":
|
|
2351
|
+
case "createLink":
|
|
2352
|
+
case "deleteLink":
|
|
2353
|
+
return [];
|
|
2354
|
+
}
|
|
2355
|
+
});
|
|
2356
|
+
return [...referenceObjectsInEdits, ...referencedObjectsInParameters];
|
|
2357
|
+
}
|
|
2358
|
+
function extractReferencedObjectsFromActionParameter2(actionParameter) {
|
|
2359
|
+
switch (actionParameter.type) {
|
|
2360
|
+
case "objectSet":
|
|
2361
|
+
case "object":
|
|
2362
|
+
return actionParameter.objectTypeApiName;
|
|
2363
|
+
case "array":
|
|
2364
|
+
return extractReferencedObjectsFromActionParameter2(actionParameter.subType);
|
|
2365
|
+
case "string":
|
|
2366
|
+
case "boolean":
|
|
2367
|
+
case "attachment":
|
|
2368
|
+
case "date":
|
|
1587
2369
|
case "double":
|
|
1588
|
-
case "float":
|
|
1589
2370
|
case "integer":
|
|
1590
|
-
return "number";
|
|
1591
2371
|
case "long":
|
|
1592
|
-
return isReturnValue ? "string" : "string | number";
|
|
1593
|
-
case "date":
|
|
1594
|
-
return "LocalDate";
|
|
1595
2372
|
case "timestamp":
|
|
1596
|
-
return
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
2373
|
+
return void 0;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
async function generatePerQueryDataFilesV2({
|
|
2377
|
+
fs: fs2,
|
|
2378
|
+
outDir: rootOutDir,
|
|
2379
|
+
ontology,
|
|
2380
|
+
importExt = ""
|
|
2381
|
+
}, v2) {
|
|
2382
|
+
const relOutDir = path16__namespace.default.join(".", "ontology", "queries");
|
|
2383
|
+
const outDir = path16__namespace.default.join(rootOutDir, "ontology", "queries");
|
|
2384
|
+
await fs2.mkdir(outDir, {
|
|
2385
|
+
recursive: true
|
|
2386
|
+
});
|
|
2387
|
+
await Promise.all(Object.values(ontology.queryTypes).map(async (query) => {
|
|
2388
|
+
await generateV2QueryFile(fs2, outDir, relOutDir, query, importExt, ontology);
|
|
2389
|
+
}));
|
|
2390
|
+
const indexFilePath = `${outDir}.ts`;
|
|
2391
|
+
await fs2.writeFile(indexFilePath, await formatTs(`
|
|
2392
|
+
${Object.values(ontology.queryTypes).map((query) => `export * from "${query.getImportPathRelTo(relOutDir)}";`).join("\n")}
|
|
2393
|
+
${Object.keys(ontology.queryTypes).length === 0 ? "export {};" : ""}
|
|
2394
|
+
`));
|
|
2395
|
+
}
|
|
2396
|
+
async function generateV2QueryFile(fs2, outDir, relOutDir, query, importExt, ontology) {
|
|
2397
|
+
const relFilePath = path16__namespace.default.join(relOutDir, `${query.shortApiName}.ts`);
|
|
2398
|
+
const objectTypes = getObjectTypeApiNamesFromQuery(query);
|
|
2399
|
+
const importObjects = getObjectImports2(ontology, objectTypes, relFilePath);
|
|
2400
|
+
const baseProps = deleteUndefineds(wireQueryTypeV2ToSdkQueryDefinitionNoParams(query.og));
|
|
2401
|
+
const outputBase = deleteUndefineds(wireQueryDataTypeToQueryDataTypeDefinition(query.output));
|
|
2402
|
+
const referencedObjectTypes = objectTypes.length > 0 ? objectTypes.map((apiNameObj) => `"${apiNameObj}"`).join("|") : "never";
|
|
2403
|
+
await fs2.writeFile(path16__namespace.default.join(outDir, `${query.shortApiName}.ts`), await formatTs(`
|
|
2404
|
+
import type { QueryDefinition , VersionBound} from "@osdk/api";
|
|
2405
|
+
import type { QueryParam, QueryResult } from "@osdk/client.api";
|
|
2406
|
+
import type { $ExpectedClientVersion } from "../../OntologyMetadata${importExt}";
|
|
2407
|
+
${importObjects}
|
|
2408
|
+
|
|
2409
|
+
export namespace ${query.shortApiName} {
|
|
2410
|
+
export interface Signature {
|
|
2411
|
+
${getDescriptionIfPresent(query.description)}
|
|
2412
|
+
(${Object.keys(query.parameters).length > 0 ? `query: ${query.paramsIdentifier}` : ""}): Promise<${getQueryParamType(ontology, wireQueryParameterV2ToQueryParameterDefinition({
|
|
2413
|
+
dataType: query.output
|
|
2414
|
+
}), "Result")}>
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2417
|
+
${Object.keys(query.parameters).length > 0 ? `
|
|
2418
|
+
export interface Parameters {
|
|
2419
|
+
${stringify(query.parameters, {
|
|
2420
|
+
"*": (parameter, formatter, apiName) => {
|
|
2421
|
+
const q = wireQueryParameterV2ToQueryParameterDefinition(parameter);
|
|
2422
|
+
return [`
|
|
2423
|
+
${queryParamJsDoc(wireQueryParameterV2ToQueryParameterDefinition(parameter), {
|
|
2424
|
+
apiName
|
|
2425
|
+
})}readonly "${apiName}"${q.nullable ? "?" : ""}`, `${getQueryParamType(ontology, q, "Param")}`];
|
|
1605
2426
|
}
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
2427
|
+
})}
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
` : ""}
|
|
2431
|
+
|
|
2432
|
+
export interface Definition extends QueryDefinition<
|
|
2433
|
+
"${query.fullApiName}",
|
|
2434
|
+
${referencedObjectTypes},
|
|
2435
|
+
${query.shortApiName}.Signature
|
|
2436
|
+
>, VersionBound<$ExpectedClientVersion>{
|
|
2437
|
+
${stringify(baseProps)},
|
|
2438
|
+
parameters: {
|
|
2439
|
+
${parameterDefsForType(ontology, query)}
|
|
2440
|
+
};
|
|
2441
|
+
output: {
|
|
2442
|
+
${stringify(outputBase)},
|
|
2443
|
+
${getLineFor__OsdkTargetType(ontology, query.output)}
|
|
2444
|
+
};
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
}
|
|
2448
|
+
|
|
2449
|
+
/** @deprecated use \`${query.shortApiName}.Signature' instead */
|
|
2450
|
+
export type ${query.shortApiName} = ${query.shortApiName}.Signature;
|
|
2451
|
+
|
|
2452
|
+
|
|
2453
|
+
|
|
2454
|
+
|
|
2455
|
+
|
|
2456
|
+
export const ${query.shortApiName}: ${query.definitionIdentifier} = {
|
|
2457
|
+
${stringify(baseProps)},
|
|
2458
|
+
parameters: {
|
|
2459
|
+
${parametersForConst(query)}
|
|
2460
|
+
},
|
|
2461
|
+
output: {
|
|
2462
|
+
${stringify(outputBase)},
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
`));
|
|
2466
|
+
}
|
|
2467
|
+
function parametersForConst(query) {
|
|
2468
|
+
return stringify(query.parameters, {
|
|
2469
|
+
"*": (parameter, formatter) => formatter(deleteUndefineds(wireQueryParameterV2ToQueryParameterDefinition(parameter)))
|
|
2470
|
+
});
|
|
2471
|
+
}
|
|
2472
|
+
function parameterDefsForType(ontology, query) {
|
|
2473
|
+
return stringify(query.parameters, {
|
|
2474
|
+
"*": (parameter, valueFormatter, apiName) => [`${queryParamJsDoc(wireQueryParameterV2ToQueryParameterDefinition(parameter), {
|
|
2475
|
+
apiName
|
|
2476
|
+
})} ${apiName}`, ` {
|
|
2477
|
+
${stringify(deleteUndefineds(wireQueryParameterV2ToQueryParameterDefinition(parameter)))},
|
|
2478
|
+
${getLineFor__OsdkTargetType(ontology, parameter.dataType)}
|
|
2479
|
+
}`]
|
|
2480
|
+
});
|
|
2481
|
+
}
|
|
2482
|
+
function getLineFor__OsdkTargetType(ontology, qdt) {
|
|
2483
|
+
if (qdt.type === "object" || qdt.type === "objectSet") {
|
|
2484
|
+
return `__OsdkTargetType?: ${ontology.requireObjectType(qdt.objectTypeApiName).getImportedDefinitionIdentifier(true)}`;
|
|
2485
|
+
}
|
|
2486
|
+
return "";
|
|
2487
|
+
}
|
|
2488
|
+
function queryParamJsDoc(param, {
|
|
2489
|
+
apiName
|
|
2490
|
+
}) {
|
|
2491
|
+
let ret = `/**
|
|
2492
|
+
`;
|
|
2493
|
+
if (param.description) {
|
|
2494
|
+
if (param.description) {
|
|
2495
|
+
ret += ` * description: ${param.description}
|
|
2496
|
+
`;
|
|
1610
2497
|
}
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
const properties = dataType.fields.map((field) => {
|
|
1615
|
-
const isNullable = isNullableQueryDataType(field.fieldType);
|
|
1616
|
-
return `${field.name}${isNullable ? "?" : ""}: ${handleQueryDataType(field.fieldType, importedObjects, isReturnValue)}`;
|
|
1617
|
-
});
|
|
1618
|
-
return `{ ${properties.join(",\n")} }`;
|
|
1619
|
-
case "union":
|
|
1620
|
-
return dataType.unionTypes.map((type) => handleQueryDataType(type, importedObjects, isReturnValue)).filter((type) => type !== "null").join("|");
|
|
1621
|
-
case "twoDimensionalAggregation":
|
|
1622
|
-
dataType.valueType;
|
|
1623
|
-
return `TwoDimensionalAggregation<
|
|
1624
|
-
${aggregationKeyToTypescriptType(dataType.keyType)},
|
|
1625
|
-
${aggregationValueToTypescriptType(dataType.valueType)}
|
|
1626
|
-
>`;
|
|
1627
|
-
case "threeDimensionalAggregation":
|
|
1628
|
-
return `ThreeDimensionalAggregation<
|
|
1629
|
-
${aggregationKeyToTypescriptType(dataType.keyType)},
|
|
1630
|
-
${aggregationKeyToTypescriptType(dataType.valueType.keyType)},
|
|
1631
|
-
${aggregationValueToTypescriptType(dataType.valueType.valueType)}
|
|
1632
|
-
>`;
|
|
1633
|
-
case "null":
|
|
1634
|
-
return "null";
|
|
1635
|
-
case "unsupported":
|
|
1636
|
-
throw new Error("Cannot generate queries for unsupported type");
|
|
1637
|
-
default:
|
|
1638
|
-
throw new Error(`Cannot generate queries for type ${dataType.type}`);
|
|
2498
|
+
} else {
|
|
2499
|
+
ret += ` * (no ontology metadata)
|
|
2500
|
+
`;
|
|
1639
2501
|
}
|
|
2502
|
+
ret += ` */
|
|
2503
|
+
`;
|
|
2504
|
+
return ret;
|
|
1640
2505
|
}
|
|
1641
|
-
function
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
return "number";
|
|
1648
|
-
case "string":
|
|
1649
|
-
return "string";
|
|
1650
|
-
case "date":
|
|
1651
|
-
return "LocalDate";
|
|
1652
|
-
case "timestamp":
|
|
1653
|
-
return "Timestamp";
|
|
1654
|
-
case "range":
|
|
1655
|
-
return `Range<${aggregationRangeToTypescriptType(keyType.subType)}>`;
|
|
1656
|
-
default:
|
|
1657
|
-
throw new Error(`Unknown TwoDimensionalAggregation keyType ${keyType.type}`);
|
|
2506
|
+
function getObjectImports2(enhancedOntology, objectTypes, filePath) {
|
|
2507
|
+
let ret = "";
|
|
2508
|
+
for (const fqObjectApiName of objectTypes) {
|
|
2509
|
+
const obj = enhancedOntology.requireObjectType(fqObjectApiName);
|
|
2510
|
+
ret += `import type { ${obj.getDefinitionIdentifier(true)} as ${obj.getImportedDefinitionIdentifier(true)} } from "${obj.getImportPathRelTo(filePath)}";
|
|
2511
|
+
`;
|
|
1658
2512
|
}
|
|
2513
|
+
return ret;
|
|
1659
2514
|
}
|
|
1660
|
-
function
|
|
1661
|
-
|
|
2515
|
+
function getQueryParamType(enhancedOntology, input, type) {
|
|
2516
|
+
let inner = `unknown /* ${input.type} */`;
|
|
2517
|
+
switch (input.type) {
|
|
1662
2518
|
case "date":
|
|
1663
|
-
|
|
2519
|
+
inner = `Query${type}.PrimitiveType<${JSON.stringify("datetime")}>`;
|
|
2520
|
+
break;
|
|
2521
|
+
case "attachment":
|
|
2522
|
+
case "boolean":
|
|
1664
2523
|
case "double":
|
|
2524
|
+
case "float":
|
|
1665
2525
|
case "integer":
|
|
1666
|
-
|
|
2526
|
+
case "long":
|
|
2527
|
+
case "string":
|
|
2528
|
+
case "struct":
|
|
2529
|
+
case "threeDimensionalAggregation":
|
|
1667
2530
|
case "timestamp":
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
2531
|
+
case "twoDimensionalAggregation":
|
|
2532
|
+
inner = `Query${type}.PrimitiveType<${JSON.stringify(input.type)}>`;
|
|
2533
|
+
break;
|
|
2534
|
+
case "object":
|
|
2535
|
+
inner = `Query${type}.ObjectType<${enhancedOntology.requireObjectType(input.object).getImportedDefinitionIdentifier(true)}>`;
|
|
2536
|
+
break;
|
|
2537
|
+
case "objectSet":
|
|
2538
|
+
inner = `Query${type}.ObjectSetType<${enhancedOntology.requireObjectType(input.objectSet).getImportedDefinitionIdentifier(true)}>`;
|
|
2539
|
+
break;
|
|
2540
|
+
case "set":
|
|
2541
|
+
inner = `${type === "Param" ? "Readonly" : ""}Set<${getQueryParamType(enhancedOntology, input.set, type)}>`;
|
|
2542
|
+
break;
|
|
2543
|
+
case "union":
|
|
2544
|
+
inner = input.union.map((u) => getQueryParamType(enhancedOntology, u, type)).join(" | ");
|
|
2545
|
+
break;
|
|
1671
2546
|
}
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
return "LocalDate";
|
|
1677
|
-
case "double":
|
|
1678
|
-
return "number";
|
|
1679
|
-
case "timestamp":
|
|
1680
|
-
return "Timestamp";
|
|
1681
|
-
default:
|
|
1682
|
-
throw new Error(`Unsupported QueryAggregationValueType ${valueType.type}`);
|
|
2547
|
+
if (input.multiplicity && type === "Param") {
|
|
2548
|
+
return `ReadonlyArray<${inner}>`;
|
|
2549
|
+
} else if (input.multiplicity) {
|
|
2550
|
+
return `Array<${inner}>`;
|
|
1683
2551
|
}
|
|
1684
|
-
|
|
1685
|
-
function sanitizeDocTypeName(type) {
|
|
1686
|
-
return type.replace(/\s/g, "");
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
|
-
// src/v1.1/generateClientSdkVersionOneDotOne.ts
|
|
1690
|
-
async function generateClientSdkVersionOneDotOne(ontology, userAgent, fs2, outDir, packageType = "commonjs") {
|
|
1691
|
-
const importExt = packageType === "module" ? ".js" : "";
|
|
1692
|
-
const objectsDir = path16__namespace.join(outDir, "ontology", "objects");
|
|
1693
|
-
const actionsDir = path16__namespace.join(outDir, "ontology", "actions");
|
|
1694
|
-
const queriesDir = path16__namespace.join(outDir, "ontology", "queries");
|
|
1695
|
-
await verifyOutDir(outDir, fs2);
|
|
1696
|
-
await fs2.mkdir(outDir, {
|
|
1697
|
-
recursive: true
|
|
1698
|
-
});
|
|
1699
|
-
const sanitizedOntology = sanitizeMetadata(ontology);
|
|
1700
|
-
await generateFoundryClientFile(fs2, outDir, importExt);
|
|
1701
|
-
await generateMetadataFile(sanitizedOntology, userAgent, fs2, outDir, importExt);
|
|
1702
|
-
await generateOntologyIndexFile(fs2, path16__namespace.join(outDir, "ontology"));
|
|
1703
|
-
await generateObjectsInterfaceFile(sanitizedOntology, fs2, objectsDir, importExt);
|
|
1704
|
-
await generateObjectsInterfaceSupportFiles(sanitizedOntology, fs2, path16__namespace.join(objectsDir, "objects-api"), importExt);
|
|
1705
|
-
await generatePerObjectInterfaceAndDataFiles(sanitizedOntology, fs2, objectsDir, importExt);
|
|
1706
|
-
await generateActions(sanitizedOntology, fs2, actionsDir, importExt);
|
|
1707
|
-
await generateBatchActions(sanitizedOntology, fs2, actionsDir, importExt);
|
|
1708
|
-
await generateBulkActions(sanitizedOntology, fs2, actionsDir, importExt);
|
|
1709
|
-
await generatePerActionDataFiles(sanitizedOntology, fs2, actionsDir, importExt, false);
|
|
1710
|
-
await generateQueries(sanitizedOntology, fs2, queriesDir, importExt);
|
|
1711
|
-
await generatePerQueryDataFiles(sanitizedOntology, fs2, queriesDir, importExt);
|
|
1712
|
-
await generateIndexFile(fs2, outDir, importExt);
|
|
1713
|
-
await generateBackCompatDeprecatedExports(fs2, outDir, importExt);
|
|
2552
|
+
return inner;
|
|
1714
2553
|
}
|
|
1715
2554
|
function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceDef, ontology, v2 = false) {
|
|
1716
|
-
const definition = deleteUndefineds(generatorConverters.__UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(interfaceDef, v2));
|
|
1717
|
-
const objectDefIdentifier =
|
|
2555
|
+
const definition = deleteUndefineds(generatorConverters.__UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(interfaceDef.og, v2));
|
|
2556
|
+
const objectDefIdentifier = interfaceDef.getDefinitionIdentifier(v2);
|
|
1718
2557
|
const parents = definition.implements?.map((p) => {
|
|
1719
2558
|
!(ontology.interfaceTypes[p] != null) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Expected to find a parent interface named ${p} in the ontology and did not.`) : invariant__default.default(false) : void 0;
|
|
1720
|
-
const it = deleteUndefineds(generatorConverters.__UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(ontology.
|
|
2559
|
+
const it = deleteUndefineds(generatorConverters.__UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(ontology.requireInterfaceType(p, true).og, v2));
|
|
1721
2560
|
return it;
|
|
1722
2561
|
}) ?? [];
|
|
1723
2562
|
const mergedProperties = {
|
|
@@ -1733,215 +2572,230 @@ function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceDef, ontology,
|
|
|
1733
2572
|
mergedProperties[apiName] = parent.properties[apiName];
|
|
1734
2573
|
}
|
|
1735
2574
|
}
|
|
1736
|
-
|
|
2575
|
+
definition.properties;
|
|
1737
2576
|
definition.properties = mergedProperties;
|
|
1738
|
-
function
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
});
|
|
2577
|
+
function maybeStripNamespace2(q) {
|
|
2578
|
+
if (interfaceDef.apiNamespace && q.startsWith(`${interfaceDef.apiNamespace}.`)) {
|
|
2579
|
+
return q.slice(interfaceDef.apiNamespace.length + 1);
|
|
2580
|
+
} else {
|
|
2581
|
+
return q;
|
|
2582
|
+
}
|
|
1745
2583
|
}
|
|
2584
|
+
const objectSetIdentifier = `${interfaceDef.shortApiName}.ObjectSet`;
|
|
2585
|
+
const propertyKeysIdentifier = `${interfaceDef.shortApiName}.PropertyKeys`;
|
|
2586
|
+
const osdkObjectPropsIdentifier = `${interfaceDef.shortApiName}.Props`;
|
|
2587
|
+
const osdkObjectStrictPropsIdentifier = `${interfaceDef.shortApiName}.StrictProps`;
|
|
2588
|
+
const osdkObjectLinksIdentifier = `OsdkObjectLinks$${objectDefIdentifier}`;
|
|
2589
|
+
const osdkObjectIdentifier = `${interfaceDef.shortApiName}.OsdkObject`;
|
|
2590
|
+
const ids = {
|
|
2591
|
+
objectDefIdentifier: `${interfaceDef.shortApiName}.Definition`,
|
|
2592
|
+
osdkObjectLinksIdentifier,
|
|
2593
|
+
osdkObjectPropsIdentifier,
|
|
2594
|
+
osdkObjectStrictPropsIdentifier,
|
|
2595
|
+
objectSetIdentifier,
|
|
2596
|
+
osdkObjectIdentifier,
|
|
2597
|
+
propertyKeysIdentifier
|
|
2598
|
+
};
|
|
1746
2599
|
function getV2Types() {
|
|
1747
|
-
return `
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
$
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
$
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
2600
|
+
return `import type {
|
|
2601
|
+
AggregateOpts as $AggregateOpts,
|
|
2602
|
+
AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy as $AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy,
|
|
2603
|
+
AggregationsResults as $AggregationsResults,
|
|
2604
|
+
Augments as $Augments,
|
|
2605
|
+
ConvertProps as $ConvertProps,
|
|
2606
|
+
DefaultToFalse as $DefaultToFalse,
|
|
2607
|
+
FetchPageArgs as $FetchPageArgs,
|
|
2608
|
+
FetchPageResult as $FetchPageResult,
|
|
2609
|
+
LinkedType as $LinkedType,
|
|
2610
|
+
LinkNames as $LinkNames,
|
|
2611
|
+
NullabilityAdherence as $NullabilityAdherence,
|
|
2612
|
+
NullabilityAdherenceDefault as $NullabilityAdherenceDefault,
|
|
2613
|
+
ObjectSet as $ObjectSet,
|
|
2614
|
+
Osdk as $Osdk,
|
|
2615
|
+
OsdkObject as $OsdkObject,
|
|
2616
|
+
OsdkObjectLinksEntry as $OsdkObjectLinksEntry,
|
|
2617
|
+
OsdkObjectLinksObject as $OsdkObjectLinksObject,
|
|
2618
|
+
OsdkObjectPropertyType as $OsdkObjectPropertyType,
|
|
2619
|
+
PageResult as $PageResult,
|
|
2620
|
+
PropertyValueClientToWire as $PropertyValueClientToWire,
|
|
2621
|
+
PropertyValueWireToClient as $PropType,
|
|
2622
|
+
Result as $Result,
|
|
2623
|
+
SelectArg as $SelectArg,
|
|
2624
|
+
SingleLinkAccessor as $SingleLinkAccessor,
|
|
2625
|
+
SingleOsdkResult as $SingleOsdkResult,
|
|
2626
|
+
ValidToFrom as $ValidToFrom,
|
|
2627
|
+
WhereClause as $WhereClause,
|
|
2628
|
+
} from "@osdk/client.api";
|
|
2629
|
+
import type * as $clientApi from "@osdk/client.api";
|
|
2630
|
+
import type {
|
|
2631
|
+
ObjectOrInterfacePropertyKeysFrom2 as $ObjectOrInterfacePropertyKeysFrom2,
|
|
2632
|
+
ObjectTypeLinkDefinition as $ObjectTypeLinkDefinition,
|
|
2633
|
+
ObjectTypeDefinition as $ObjectTypeDefinition,
|
|
2634
|
+
InterfaceDefinition as $InterfaceDefinition,
|
|
2635
|
+
} from "@osdk/api";
|
|
2636
|
+
|
|
2637
|
+
|
|
2638
|
+
|
|
2639
|
+
${Object.keys(definition.links).length === 0 ? `export type ${osdkObjectLinksIdentifier} = never;` : `
|
|
2640
|
+
export interface ${osdkObjectLinksIdentifier} {
|
|
2641
|
+
${stringify(definition.links, {
|
|
2642
|
+
"*": (definition2) => {
|
|
2643
|
+
const linkTarget = ontology.requireObjectType(definition2.targetType).getImportedDefinitionIdentifier(v2);
|
|
2644
|
+
return `${definition2.multiplicity ? `${linkTarget}["objectSet"]` : `SingleLinkAccessor<${linkTarget}>`}
|
|
2645
|
+
`;
|
|
2646
|
+
}
|
|
1764
2647
|
})}
|
|
1765
|
-
|
|
2648
|
+
}
|
|
2649
|
+
`}
|
|
2650
|
+
|
|
2651
|
+
export namespace ${interfaceDef.shortApiName} {
|
|
2652
|
+
|
|
2653
|
+
${createPropertyKeys(interfaceDef)}
|
|
2654
|
+
|
|
2655
|
+
|
|
2656
|
+
${createProps(interfaceDef, "Props", false)}
|
|
2657
|
+
${createProps(interfaceDef, "StrictProps", true)}
|
|
2658
|
+
|
|
2659
|
+
|
|
2660
|
+
${createObjectSet(interfaceDef, ids)}
|
|
2661
|
+
|
|
2662
|
+
${createDefinition(interfaceDef, ontology, "Definition", ids)}
|
|
2663
|
+
|
|
2664
|
+
${createOsdkObject(interfaceDef, "OsdkObject", ids)}
|
|
2665
|
+
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
|
|
2669
|
+
|
|
2670
|
+
|
|
2671
|
+
/** @deprecated use ${interfaceDef.shortApiName}.Definition **/
|
|
2672
|
+
export type ${objectDefIdentifier} = ${interfaceDef.shortApiName}.Definition;
|
|
2673
|
+
|
|
2674
|
+
|
|
2675
|
+
|
|
1766
2676
|
|
|
1767
2677
|
`;
|
|
1768
2678
|
}
|
|
1769
2679
|
const imports = [];
|
|
1770
2680
|
return `${imports.join("\n")}
|
|
1771
|
-
|
|
1772
2681
|
${v2 ? getV2Types() : ""}
|
|
1773
2682
|
|
|
1774
|
-
export const ${
|
|
2683
|
+
export const ${interfaceDef.shortApiName}: ${interfaceDef.shortApiName}.Definition = {
|
|
1775
2684
|
osdkMetadata: $osdkMetadata,
|
|
2685
|
+
objectSet: undefined as any,
|
|
2686
|
+
props: undefined as any,
|
|
2687
|
+
strictProps: undefined as any,
|
|
1776
2688
|
${stringify(definition, {
|
|
1777
|
-
osdkMetadata: () => void 0
|
|
2689
|
+
osdkMetadata: () => void 0,
|
|
2690
|
+
properties: (properties) => `{
|
|
2691
|
+
${stringify(properties, {
|
|
2692
|
+
"*": (propertyDefinition, _, key) => [`"${maybeStripNamespace2(key)}"`, _(propertyDefinition)]
|
|
2693
|
+
})}
|
|
2694
|
+
}`
|
|
1778
2695
|
})}
|
|
1779
2696
|
|
|
1780
2697
|
};`;
|
|
1781
2698
|
}
|
|
1782
|
-
var ExpectedOsdkVersion = "0.21.0";
|
|
1783
|
-
async function generateOntologyMetadataFile(ontology, userAgent, fs2, outDir) {
|
|
1784
|
-
fs2.writeFile(path16__namespace.default.join(outDir, "OntologyMetadata.ts"), await formatTs(`
|
|
1785
|
-
import { OntologyMetadata as OM } from "@osdk/api";
|
|
1786
|
-
|
|
1787
|
-
export type $ExpectedClientVersion = "${ExpectedOsdkVersion}";
|
|
1788
|
-
export const $osdkMetadata = { extraUserAgent: "${userAgent}" };
|
|
1789
|
-
|
|
1790
|
-
export interface OntologyMetadata extends OM<$ExpectedClientVersion> {};
|
|
1791
|
-
|
|
1792
|
-
export const OntologyMetadata: OntologyMetadata = {
|
|
1793
|
-
expectsClientVersion: "${ExpectedOsdkVersion}",
|
|
1794
|
-
ontologyRid: "${ontology.ontology.rid}",
|
|
1795
|
-
ontologyApiName: "${ontology.ontology.apiName}",
|
|
1796
|
-
userAgent: "${userAgent}",
|
|
1797
|
-
};
|
|
1798
|
-
`));
|
|
1799
|
-
}
|
|
1800
2699
|
|
|
1801
2700
|
// src/v2.0/generateClientSdkVersionTwoPointZero.ts
|
|
1802
|
-
async function
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
await fs2.mkdir(outDir, {
|
|
1811
|
-
recursive: true
|
|
1812
|
-
});
|
|
1813
|
-
fs2.writeFile(path16__namespace.default.join(outDir, "index.ts"), await formatTs(`
|
|
1814
|
-
export { Ontology } from "./Ontology${importExt}";
|
|
1815
|
-
export * from "./ontology/actions/index${importExt}";
|
|
2701
|
+
async function generateRootIndexTsFile({
|
|
2702
|
+
fs: fs2,
|
|
2703
|
+
outDir,
|
|
2704
|
+
importExt,
|
|
2705
|
+
ontologyApiNamespace
|
|
2706
|
+
}) {
|
|
2707
|
+
fs2.writeFile(path16__namespace.default.join(outDir, "index.ts"), await formatTs(`${ontologyApiNamespace == null ? `export { $ontologyRid } from "./OntologyMetadata${importExt}";` : ``}
|
|
2708
|
+
export * from "./ontology/actions${importExt}";
|
|
1816
2709
|
export * from "./ontology/objects${importExt}";
|
|
1817
2710
|
export * from "./ontology/interfaces${importExt}";
|
|
1818
|
-
export * from "./ontology/queries
|
|
1819
|
-
`));
|
|
1820
|
-
await generateOntologyMetadataFile(sanitizedOntology, userAgent, fs2, outDir);
|
|
1821
|
-
await fs2.writeFile(path16__namespace.default.join(outDir, "Ontology.ts"), await formatTs(`
|
|
1822
|
-
import type { OntologyDefinition } from "@osdk/api";
|
|
1823
|
-
import * as Actions from "./ontology/actions/index${importExt}";
|
|
1824
|
-
import * as Objects from "./ontology/objects${importExt}";
|
|
1825
|
-
import * as Interfaces from "./ontology/interfaces${importExt}";
|
|
1826
|
-
import * as Queries from "./ontology/queries/index${importExt}";
|
|
1827
|
-
import { OntologyMetadata } from "./OntologyMetadata${importExt}";
|
|
1828
|
-
|
|
1829
|
-
export interface Ontology extends OntologyDefinition<${stringUnionFrom2(objectNames)}> {
|
|
1830
|
-
metadata: OntologyMetadata,
|
|
1831
|
-
objects: {
|
|
1832
|
-
${objectNames.map((objectName) => {
|
|
1833
|
-
return `${objectName}: Objects.${objectName}`;
|
|
1834
|
-
}).join(",\n")}
|
|
1835
|
-
},
|
|
1836
|
-
actions: {
|
|
1837
|
-
${actionNames.map((actionName) => {
|
|
1838
|
-
return `${actionName}: typeof Actions.${actionName}`;
|
|
1839
|
-
}).join(",\n")}
|
|
1840
|
-
},
|
|
1841
|
-
queries: {
|
|
1842
|
-
${queryNames.map((queryName) => {
|
|
1843
|
-
return `${queryName}: typeof Queries.${queryName}`;
|
|
1844
|
-
}).join(",\n")}
|
|
1845
|
-
},
|
|
1846
|
-
interfaces: {
|
|
1847
|
-
${interfaceNames.map((objectName) => {
|
|
1848
|
-
return `${objectName}: Interfaces.${objectName}`;
|
|
1849
|
-
}).join(",\n")}
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
|
|
1853
|
-
export const Ontology: Ontology = {
|
|
1854
|
-
metadata: OntologyMetadata,
|
|
1855
|
-
objects: {
|
|
1856
|
-
${objectNames.map((objectName) => {
|
|
1857
|
-
return `${objectName}: Objects.${objectName}`;
|
|
1858
|
-
}).join(",\n")}
|
|
1859
|
-
|
|
1860
|
-
},
|
|
1861
|
-
actions: {
|
|
1862
|
-
${actionNames.map((actionName) => {
|
|
1863
|
-
return `${actionName}: Actions.${actionName}`;
|
|
1864
|
-
}).join(",\n")}
|
|
1865
|
-
},
|
|
1866
|
-
queries: {
|
|
1867
|
-
${queryNames.map((queryName) => {
|
|
1868
|
-
return `${queryName}: Queries.${queryName}`;
|
|
1869
|
-
}).join(",\n")}
|
|
1870
|
-
},
|
|
1871
|
-
interfaces: {
|
|
1872
|
-
${interfaceNames.map((objectName) => {
|
|
1873
|
-
return `${objectName}: Interfaces.${objectName}`;
|
|
1874
|
-
}).join(",\n")}
|
|
1875
|
-
|
|
1876
|
-
}
|
|
1877
|
-
};
|
|
1878
|
-
|
|
2711
|
+
export * from "./ontology/queries${importExt}";
|
|
1879
2712
|
`));
|
|
2713
|
+
}
|
|
2714
|
+
async function generateEachObjectFile(ctx) {
|
|
2715
|
+
const {
|
|
2716
|
+
fs: fs2,
|
|
2717
|
+
outDir,
|
|
2718
|
+
ontology,
|
|
2719
|
+
importExt
|
|
2720
|
+
} = ctx;
|
|
1880
2721
|
await fs2.mkdir(path16__namespace.default.join(outDir, "ontology", "objects"), {
|
|
1881
2722
|
recursive: true
|
|
1882
2723
|
});
|
|
1883
|
-
for (const
|
|
1884
|
-
const
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
import {
|
|
2724
|
+
for (const obj of Object.values(ontology.objectTypes)) {
|
|
2725
|
+
const relPath = path16__namespace.default.join(".", "ontology", `objects`, `${obj.shortApiName}.ts`);
|
|
2726
|
+
const outFilePath = path16__namespace.default.join(outDir, relPath);
|
|
2727
|
+
await fs2.writeFile(outFilePath, await formatTs(`
|
|
2728
|
+
import type { VersionBound as $VersionBound, PropertyDef as $PropertyDef } from "@osdk/api";
|
|
2729
|
+
import type { Osdk } from "@osdk/client.api";
|
|
1888
2730
|
import { $osdkMetadata } from "../../OntologyMetadata${importExt}";
|
|
1889
2731
|
import type { $ExpectedClientVersion } from "../../OntologyMetadata${importExt}";
|
|
1890
|
-
|
|
1891
|
-
${wireObjectTypeV2ToSdkObjectConst(obj, importExt, true)}
|
|
2732
|
+
${wireObjectTypeV2ToSdkObjectConstV2(obj.og, ctx, relPath)}
|
|
1892
2733
|
`));
|
|
1893
2734
|
}
|
|
1894
|
-
|
|
2735
|
+
}
|
|
2736
|
+
async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs2, outDir, packageType = "commonjs", ontologyApiNamespace, apiNamespacePackageMap = /* @__PURE__ */ new Map()) {
|
|
2737
|
+
const importExt = packageType === "module" ? ".js" : "";
|
|
2738
|
+
await verifyOutDir(outDir, fs2);
|
|
2739
|
+
const sanitizedOntology = sanitizeMetadata(ontology);
|
|
2740
|
+
await fs2.mkdir(outDir, {
|
|
2741
|
+
recursive: true
|
|
2742
|
+
});
|
|
2743
|
+
const enhancedOntology = enhanceOntology(sanitizedOntology, ontologyApiNamespace, apiNamespacePackageMap, importExt);
|
|
2744
|
+
const ctx = {
|
|
2745
|
+
sanitizedOntology,
|
|
2746
|
+
ontology: enhancedOntology,
|
|
2747
|
+
importExt,
|
|
2748
|
+
fs: fs2,
|
|
2749
|
+
outDir,
|
|
2750
|
+
ontologyApiNamespace,
|
|
2751
|
+
apiNamespacePackageMap
|
|
2752
|
+
};
|
|
2753
|
+
await generateRootIndexTsFile(ctx);
|
|
2754
|
+
await generateOntologyMetadataFile(ctx, userAgent);
|
|
2755
|
+
await generateEachObjectFile(ctx);
|
|
2756
|
+
await generateOntologyInterfaces(ctx);
|
|
1895
2757
|
const actionsDir = path16__namespace.default.join(outDir, "ontology", "actions");
|
|
1896
2758
|
await fs2.mkdir(actionsDir, {
|
|
1897
2759
|
recursive: true
|
|
1898
2760
|
});
|
|
1899
|
-
await generatePerActionDataFiles(
|
|
2761
|
+
await generatePerActionDataFiles(ctx);
|
|
1900
2762
|
await fs2.writeFile(path16__namespace.default.join(outDir, "ontology", "objects.ts"), await formatTs(`
|
|
1901
|
-
${Object.
|
|
2763
|
+
${Object.values(enhancedOntology.objectTypes).map((objType) => `export * from "./objects/${objType.shortApiName}${importExt}";`).join("\n")}
|
|
1902
2764
|
${Object.keys(ontology.objectTypes).length === 0 ? "export {};" : ""}
|
|
1903
2765
|
`));
|
|
1904
|
-
|
|
1905
|
-
await fs2.mkdir(queriesDir, {
|
|
1906
|
-
recursive: true
|
|
1907
|
-
});
|
|
1908
|
-
await generatePerQueryDataFiles(sanitizedOntology, fs2, queriesDir, importExt, true);
|
|
1909
|
-
}
|
|
1910
|
-
function stringUnionFrom2(values) {
|
|
1911
|
-
if (values.length === 0) {
|
|
1912
|
-
return "never";
|
|
1913
|
-
} else {
|
|
1914
|
-
return values.map((v) => `"${v}"`).join("|");
|
|
1915
|
-
}
|
|
2766
|
+
await generatePerQueryDataFilesV2(ctx);
|
|
1916
2767
|
}
|
|
1917
|
-
async function generateOntologyInterfaces(
|
|
2768
|
+
async function generateOntologyInterfaces({
|
|
2769
|
+
fs: fs2,
|
|
2770
|
+
outDir,
|
|
2771
|
+
ontology,
|
|
2772
|
+
importExt
|
|
2773
|
+
}) {
|
|
1918
2774
|
const interfacesDir = path16__namespace.default.join(outDir, "ontology", "interfaces");
|
|
1919
2775
|
await fs2.mkdir(interfacesDir, {
|
|
1920
2776
|
recursive: true
|
|
1921
2777
|
});
|
|
1922
|
-
for (const
|
|
1923
|
-
|
|
1924
|
-
await fs2.writeFile(path16__namespace.default.join(interfacesDir, `${name}.ts`), await formatTs(`
|
|
2778
|
+
for (const obj of Object.values(ontology.interfaceTypes)) {
|
|
2779
|
+
await fs2.writeFile(path16__namespace.default.join(interfacesDir, `${obj.shortApiName}.ts`), await formatTs(`
|
|
1925
2780
|
|
|
1926
|
-
import type {
|
|
2781
|
+
import type { PropertyDef as $PropertyDef, VersionBound as $VersionBound } from "@osdk/api";
|
|
1927
2782
|
import { $osdkMetadata, $expectedClientVersion } from "../../OntologyMetadata${importExt}";
|
|
1928
2783
|
import type { $ExpectedClientVersion } from "../../OntologyMetadata${importExt}";
|
|
1929
|
-
|
|
1930
2784
|
${__UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(obj, ontology, true)}
|
|
1931
2785
|
`));
|
|
1932
2786
|
}
|
|
1933
2787
|
await fs2.writeFile(interfacesDir + ".ts", await formatTs(`
|
|
1934
|
-
${Object.
|
|
1935
|
-
${Object.keys(ontology.interfaceTypes
|
|
2788
|
+
${Object.values(ontology.interfaceTypes).map((interfaceType) => `export * from "./interfaces/${interfaceType.shortApiName}${importExt}";`).join("\n")}
|
|
2789
|
+
${Object.keys(ontology.interfaceTypes).length === 0 ? "export {}" : ""}
|
|
1936
2790
|
`));
|
|
1937
2791
|
}
|
|
1938
2792
|
|
|
1939
2793
|
// src/generateClientSdkPackage.ts
|
|
1940
|
-
async function generateClientSdkPackage(packageName, packageVersion, sdkVersion, baseOutDir, ontology, minimalFs, dependencyVersions, cliVersion) {
|
|
2794
|
+
async function generateClientSdkPackage(packageName, packageVersion, sdkVersion, baseOutDir, ontology, minimalFs, dependencyVersions, cliVersion, ontologyApiNamespace, apiNamespacePackageMap) {
|
|
1941
2795
|
if (!packageName) throw new Error("Package name is require");
|
|
1942
2796
|
for (const packageType of ["module", "commonjs"]) {
|
|
1943
2797
|
const outDir = path16__namespace.join(baseOutDir, "dist", packageType);
|
|
1944
|
-
await (sdkVersion === "1.1" ? generateClientSdkVersionOneDotOne : sdkVersion === "2.0" ? generateClientSdkVersionTwoPointZero : void 0)(ontology, `typescript-sdk/${packageVersion} osdk-cli/${cliVersion}`, minimalFs, outDir, packageType);
|
|
2798
|
+
await (sdkVersion === "1.1" ? generateClientSdkVersionOneDotOne : sdkVersion === "2.0" ? generateClientSdkVersionTwoPointZero : void 0)(ontology, `typescript-sdk/${packageVersion} osdk-cli/${cliVersion}`, minimalFs, outDir, packageType, ontologyApiNamespace, apiNamespacePackageMap);
|
|
1945
2799
|
await fs__namespace.promises.mkdir(outDir, {
|
|
1946
2800
|
recursive: true
|
|
1947
2801
|
});
|