@osdk/generator 1.5.0 → 1.7.0
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/build/js/index.cjs +152 -234
- package/build/js/index.cjs.map +1 -1
- package/build/js/index.mjs +152 -234
- package/build/js/index.mjs.map +1 -1
- package/build/types/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.d.ts +1 -1
- package/build/types/shared/index.d.ts +0 -2
- package/build/types/shared/wireObjectTypeV2ToSdkObjectConst.d.ts +1 -0
- package/build/types/util/stringify.d.ts +19 -0
- package/build/types/util/test/TodoWireOntology.d.ts +2 -0
- package/changelog/1.6.0/pr-67.v2.yml +5 -0
- package/changelog/1.6.0/pr-83.v2.yml +5 -0
- package/changelog/1.6.0/pr-88.v2.yml +5 -0
- package/changelog/1.6.0/pr-89.v2.yml +5 -0
- package/changelog/1.7.0/pr-101.v2.yml +5 -0
- package/changelog/1.7.0/pr-102.v2.yml +5 -0
- package/changelog/1.7.0/pr-113.v2.yml +5 -0
- package/changelog/1.7.0/pr-120.v2.yml +5 -0
- package/changelog/1.7.0/pr-121.v2.yml +5 -0
- package/changelog/1.7.0/pr-124.v2.yml +5 -0
- package/package.json +5 -4
- package/build/types/shared/wireObjectTypeV2ToSdkObjectDefinition.d.ts +0 -3
- package/build/types/shared/wirePropertyV2ToSdkPrimaryKeyTypeDefinition.d.ts +0 -3
- package/build/types/shared/wirePropertyV2ToSdkPropertyDefinition.d.ts +0 -3
- package/build/types/v2.0/wireObjectTypeV2ToObjectDefinitionInterfaceString.d.ts +0 -2
package/build/js/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var path15 = require('path');
|
|
4
4
|
var prettier = require('prettier');
|
|
5
5
|
var organizeImports = require('prettier-plugin-organize-imports');
|
|
6
|
+
var generatorConverters = require('@osdk/generator-converters');
|
|
6
7
|
|
|
7
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
9
|
|
|
@@ -804,32 +805,12 @@ function wireActionTypeV2ToSdkActionDefinition(input) {
|
|
|
804
805
|
};
|
|
805
806
|
}
|
|
806
807
|
function wireActionParameterV2ToSdkParameterDefinition(value) {
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
case "double":
|
|
814
|
-
case "integer":
|
|
815
|
-
case "long":
|
|
816
|
-
case "objectSet":
|
|
817
|
-
case "timestamp":
|
|
818
|
-
case "marking":
|
|
819
|
-
return {
|
|
820
|
-
multiplicity: false,
|
|
821
|
-
type: actionPropertyToSdkPropertyDefinition(value.dataType),
|
|
822
|
-
nullable: value.required ? false : true,
|
|
823
|
-
description: value.description
|
|
824
|
-
};
|
|
825
|
-
case "array":
|
|
826
|
-
return {
|
|
827
|
-
multiplicity: true,
|
|
828
|
-
type: actionPropertyToSdkPropertyDefinition(value.dataType.subType),
|
|
829
|
-
nullable: value.required ? false : true,
|
|
830
|
-
description: value.description
|
|
831
|
-
};
|
|
832
|
-
}
|
|
808
|
+
return {
|
|
809
|
+
multiplicity: value.dataType.type === "array",
|
|
810
|
+
type: actionPropertyToSdkPropertyDefinition(value.dataType.type === "array" ? value.dataType.subType : value.dataType),
|
|
811
|
+
nullable: !value.required,
|
|
812
|
+
description: value.description
|
|
813
|
+
};
|
|
833
814
|
}
|
|
834
815
|
function actionPropertyToSdkPropertyDefinition(parameterType) {
|
|
835
816
|
switch (parameterType.type) {
|
|
@@ -884,6 +865,80 @@ function deleteUndefineds(obj) {
|
|
|
884
865
|
return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== void 0));
|
|
885
866
|
}
|
|
886
867
|
|
|
868
|
+
// src/util/stringify.ts
|
|
869
|
+
var defaultCustomizer = (value, defaultValueFormatter, key, defaultKeyFormatter) => {
|
|
870
|
+
return [defaultKeyFormatter(key), defaultValueFormatter(value)];
|
|
871
|
+
};
|
|
872
|
+
function stringify(obj, customizer = {}, separator = ",\n") {
|
|
873
|
+
const defaultKeyFormatter = (key) => `${JSON.stringify(key)}`;
|
|
874
|
+
const entries = [];
|
|
875
|
+
const sortedKeys = Object.keys(obj).sort((a, b) => a.localeCompare(b));
|
|
876
|
+
for (const key of sortedKeys) {
|
|
877
|
+
const value = obj[key];
|
|
878
|
+
const res = (customizer[key] ?? customizer["*"] ?? defaultCustomizer)(value, (value2) => JSON.stringify(value2, null, 2), key, defaultKeyFormatter);
|
|
879
|
+
if (res) {
|
|
880
|
+
if (typeof res === "string") {
|
|
881
|
+
entries.push(`${defaultKeyFormatter(key)}: ${res}`);
|
|
882
|
+
} else {
|
|
883
|
+
entries.push(`${res[0]}: ${res[1]}`);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
return entries.join(separator);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
// src/shared/wireObjectTypeV2ToSdkObjectConst.ts
|
|
891
|
+
function getObjectDefIdentifier(name, v2) {
|
|
892
|
+
return v2 ? name : `${name}Def`;
|
|
893
|
+
}
|
|
894
|
+
function wireObjectTypeV2ToSdkObjectConst(object, importExt, v2 = false) {
|
|
895
|
+
const uniqueLinkTargetTypes = new Set(object.linkTypes.map((a) => a.objectTypeApiName));
|
|
896
|
+
const definition = deleteUndefineds(generatorConverters.wireObjectTypeFullMetadataToSdkObjectTypeDefinition(object, v2));
|
|
897
|
+
const objectDefIdentifier = getObjectDefIdentifier(object.objectType.apiName, v2);
|
|
898
|
+
function getV1Types() {
|
|
899
|
+
return `
|
|
900
|
+
export interface ${objectDefIdentifier} extends ObjectTypeDefinition<"${object.objectType.apiName}", ${object.objectType.apiName}> {
|
|
901
|
+
${stringify(definition, {
|
|
902
|
+
links: (_value) => `{
|
|
903
|
+
${stringify(definition.links, {
|
|
904
|
+
"*": (definition2) => `ObjectTypeLinkDefinition<${getObjectDefIdentifier(definition2.targetType, v2)}, ${definition2.multiplicity}>`
|
|
905
|
+
})}
|
|
906
|
+
}`
|
|
907
|
+
})}
|
|
908
|
+
}
|
|
909
|
+
`;
|
|
910
|
+
}
|
|
911
|
+
function getV2Types() {
|
|
912
|
+
return `
|
|
913
|
+
export interface ${objectDefIdentifier} extends ObjectTypeDefinition<"${object.objectType.apiName}", ${object.objectType.apiName}> {
|
|
914
|
+
${stringify(definition, {
|
|
915
|
+
type: () => void 0,
|
|
916
|
+
apiName: () => void 0,
|
|
917
|
+
links: (_value) => `{
|
|
918
|
+
${stringify(definition.links, {
|
|
919
|
+
"*": (definition2) => `ObjectTypeLinkDefinition<${getObjectDefIdentifier(definition2.targetType, v2)}, ${definition2.multiplicity}>`
|
|
920
|
+
})}
|
|
921
|
+
}`,
|
|
922
|
+
properties: (_value) => `{
|
|
923
|
+
${stringify(definition.properties, {
|
|
924
|
+
"*": (propertyDefinition) => `PropertyDef<"${propertyDefinition.type}", "${propertyDefinition.nullable ? "nullable" : "non-nullable"}", "${propertyDefinition.multiplicity ? "array" : "single"}">`
|
|
925
|
+
})}
|
|
926
|
+
}`
|
|
927
|
+
})}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
`;
|
|
931
|
+
}
|
|
932
|
+
const imports = Array.from(uniqueLinkTargetTypes).filter((type) => type !== definition.apiName).map((type) => `import type { ${getObjectDefIdentifier(type, v2)} } from "./${type}${importExt}";`);
|
|
933
|
+
return `${imports.join("\n")}
|
|
934
|
+
|
|
935
|
+
${v2 ? getV2Types() : getV1Types()}
|
|
936
|
+
|
|
937
|
+
export const ${object.objectType.apiName}: ${objectDefIdentifier} = {
|
|
938
|
+
${stringify(definition)}
|
|
939
|
+
};`;
|
|
940
|
+
}
|
|
941
|
+
|
|
887
942
|
// src/util/reservedKeywords.ts
|
|
888
943
|
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"]);
|
|
889
944
|
function isReservedKeyword(name) {
|
|
@@ -933,7 +988,7 @@ function wirePropertyTypeV2ToTypeScriptType(property) {
|
|
|
933
988
|
case "date":
|
|
934
989
|
return "LocalDate";
|
|
935
990
|
case "decimal":
|
|
936
|
-
return "
|
|
991
|
+
return "string";
|
|
937
992
|
case "double":
|
|
938
993
|
return "number";
|
|
939
994
|
case "float":
|
|
@@ -943,7 +998,7 @@ function wirePropertyTypeV2ToTypeScriptType(property) {
|
|
|
943
998
|
case "geoshape":
|
|
944
999
|
return "GeoShape";
|
|
945
1000
|
case "long":
|
|
946
|
-
return "
|
|
1001
|
+
return "string";
|
|
947
1002
|
case "short":
|
|
948
1003
|
return "number";
|
|
949
1004
|
case "timestamp":
|
|
@@ -966,9 +1021,6 @@ function getDescriptionIfPresent(description, includeNewline) {
|
|
|
966
1021
|
}
|
|
967
1022
|
|
|
968
1023
|
// src/v1.1/generatePerActionDataFiles.ts
|
|
969
|
-
function stringifyWithoutOuterBraces(obj) {
|
|
970
|
-
return JSON.stringify(obj, null, 2).replace(/^\{\n/, "").replace(/\n\}$/, "");
|
|
971
|
-
}
|
|
972
1024
|
async function generatePerActionDataFiles(ontology, fs, outDir, importExt, v2) {
|
|
973
1025
|
await fs.mkdir(outDir, {
|
|
974
1026
|
recursive: true
|
|
@@ -986,30 +1038,30 @@ async function generatePerActionDataFiles(ontology, fs, outDir, importExt, v2) {
|
|
|
986
1038
|
const paramsIdentifier = `${action.apiName}$Params`;
|
|
987
1039
|
function createParamsDef() {
|
|
988
1040
|
const entries = Object.entries(parameters);
|
|
1041
|
+
entries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
989
1042
|
if (entries.length === 0) {
|
|
990
1043
|
return `// Represents the definition of the parameters for the action
|
|
991
1044
|
export type ${paramsDefIdentifier} = Record<string, never>;`;
|
|
992
1045
|
}
|
|
993
1046
|
return `// Represents the definition of the parameters for the action
|
|
994
1047
|
export type ${paramsDefIdentifier} = {
|
|
995
|
-
${
|
|
996
|
-
const {
|
|
997
|
-
type,
|
|
998
|
-
...remain
|
|
999
|
-
} = value;
|
|
1000
|
-
let q;
|
|
1001
|
-
if (typeof type === "string") {
|
|
1002
|
-
q = JSON.stringify(type);
|
|
1003
|
-
} else if (type.type === "object") {
|
|
1004
|
-
q = `ObjectActionDataType<"${type.object}", ${type.object}Def>`;
|
|
1005
|
-
} else if (type.type === "objectSet") {
|
|
1006
|
-
q = `ObjectSetActionDataType<"${type.objectSet}", ${type.objectSet}Def>`;
|
|
1007
|
-
}
|
|
1048
|
+
${entries.map(([key, value]) => {
|
|
1008
1049
|
return `"${key}": {
|
|
1009
|
-
|
|
1010
|
-
|
|
1050
|
+
${stringify(value, {
|
|
1051
|
+
description: (value2, d) => value2 ? d(value2) : void 0,
|
|
1052
|
+
// trick to remove undefineds
|
|
1053
|
+
type: (type) => {
|
|
1054
|
+
if (typeof type === "string") {
|
|
1055
|
+
return JSON.stringify(type);
|
|
1056
|
+
} else if (type.type === "object") {
|
|
1057
|
+
return `ObjectActionDataType<"${type.object}", ${getObjectDefIdentifier(type.object, v2)}>`;
|
|
1058
|
+
} else if (type.type === "objectSet") {
|
|
1059
|
+
return `ObjectSetActionDataType<"${type.objectSet}", ${getObjectDefIdentifier(type.objectSet, v2)}>`;
|
|
1011
1060
|
}
|
|
1012
|
-
|
|
1061
|
+
return void 0;
|
|
1062
|
+
}
|
|
1063
|
+
})}
|
|
1064
|
+
}`;
|
|
1013
1065
|
}).join(";\n")}
|
|
1014
1066
|
}`;
|
|
1015
1067
|
}
|
|
@@ -1032,7 +1084,7 @@ async function generatePerActionDataFiles(ontology, fs, outDir, importExt, v2) {
|
|
|
1032
1084
|
|
|
1033
1085
|
// Represents the definition of the action
|
|
1034
1086
|
export interface ${actionDefIdentifier} extends ActionDefinition<"${action.apiName}", ${uniqueApiNamesString}, ${action.apiName}>{
|
|
1035
|
-
${Object.entries(actionDefSansParameters).map(([key, value]) => {
|
|
1087
|
+
${Object.entries(actionDefSansParameters).sort((a, b) => a[0].localeCompare(b[0])).map(([key, value]) => {
|
|
1036
1088
|
return `${key}: ${JSON.stringify(value)};`;
|
|
1037
1089
|
}).join("\n")}
|
|
1038
1090
|
parameters: ${paramsDefIdentifier}
|
|
@@ -1047,8 +1099,8 @@ async function generatePerActionDataFiles(ontology, fs, outDir, importExt, v2) {
|
|
|
1047
1099
|
const referencedObjectDefs = /* @__PURE__ */ new Set();
|
|
1048
1100
|
for (const p of Object.values(action.parameters)) {
|
|
1049
1101
|
if (p.dataType.type === "object" || p.dataType.type === "objectSet") {
|
|
1050
|
-
referencedObjectDefs.add(p.dataType.objectApiName
|
|
1051
|
-
referencedObjectDefs.add(p.dataType.objectTypeApiName
|
|
1102
|
+
referencedObjectDefs.add(getObjectDefIdentifier(p.dataType.objectApiName, v2));
|
|
1103
|
+
referencedObjectDefs.add(getObjectDefIdentifier(p.dataType.objectTypeApiName, v2));
|
|
1052
1104
|
}
|
|
1053
1105
|
}
|
|
1054
1106
|
const importObjects = referencedObjectDefs.size > 0 ? `import type {${[...referencedObjectDefs].join(",")}} from "../objects${importExt}";` : "";
|
|
@@ -1065,6 +1117,7 @@ async function generatePerActionDataFiles(ontology, fs, outDir, importExt, v2) {
|
|
|
1065
1117
|
}));
|
|
1066
1118
|
await fs.writeFile(path15__namespace.default.join(outDir, `index.ts`), await formatTs(`
|
|
1067
1119
|
${Object.values(ontology.actionTypes).map((action) => `export {${action.apiName}} from "./${action.apiName}${importExt}";`).join("\n")}
|
|
1120
|
+
${Object.keys(ontology.actionTypes).length === 0 ? "export {};" : ""}
|
|
1068
1121
|
`));
|
|
1069
1122
|
}
|
|
1070
1123
|
function extractReferencedObjectsFromAction(actionType) {
|
|
@@ -1106,157 +1159,6 @@ function extractReferencedObjectsFromActionParameter(actionParameter) {
|
|
|
1106
1159
|
return void 0;
|
|
1107
1160
|
}
|
|
1108
1161
|
}
|
|
1109
|
-
|
|
1110
|
-
// src/shared/wirePropertyV2ToSdkPrimaryKeyTypeDefinition.ts
|
|
1111
|
-
function wirePropertyV2ToSdkPrimaryKeyTypeDefinition(input) {
|
|
1112
|
-
switch (input.dataType.type) {
|
|
1113
|
-
case "integer":
|
|
1114
|
-
case "double":
|
|
1115
|
-
case "string":
|
|
1116
|
-
case "boolean":
|
|
1117
|
-
case "attachment":
|
|
1118
|
-
case "byte":
|
|
1119
|
-
case "decimal":
|
|
1120
|
-
case "float":
|
|
1121
|
-
case "geopoint":
|
|
1122
|
-
case "geoshape":
|
|
1123
|
-
case "long":
|
|
1124
|
-
case "short": {
|
|
1125
|
-
return input.dataType.type;
|
|
1126
|
-
}
|
|
1127
|
-
case "date": {
|
|
1128
|
-
return "datetime";
|
|
1129
|
-
}
|
|
1130
|
-
case "timestamp": {
|
|
1131
|
-
return "timestamp";
|
|
1132
|
-
}
|
|
1133
|
-
case "timeseries":
|
|
1134
|
-
case "array":
|
|
1135
|
-
case "marking":
|
|
1136
|
-
throw new Error(`Type not supported for primaryKey: ${input.dataType.type}`);
|
|
1137
|
-
default:
|
|
1138
|
-
input.dataType;
|
|
1139
|
-
throw new Error(`Unknown type encountered for primaryKey: ${input.dataType}`);
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
// src/shared/wirePropertyV2ToSdkPropertyDefinition.ts
|
|
1144
|
-
function wirePropertyV2ToSdkPropertyDefinition(input, isNullable = true) {
|
|
1145
|
-
switch (input.dataType.type) {
|
|
1146
|
-
case "integer":
|
|
1147
|
-
case "string":
|
|
1148
|
-
case "byte":
|
|
1149
|
-
case "decimal":
|
|
1150
|
-
case "double":
|
|
1151
|
-
case "float":
|
|
1152
|
-
case "long":
|
|
1153
|
-
case "short":
|
|
1154
|
-
case "boolean":
|
|
1155
|
-
case "date":
|
|
1156
|
-
case "attachment":
|
|
1157
|
-
case "geopoint":
|
|
1158
|
-
case "geoshape":
|
|
1159
|
-
case "timestamp":
|
|
1160
|
-
case "timeseries":
|
|
1161
|
-
case "marking":
|
|
1162
|
-
return {
|
|
1163
|
-
multiplicity: false,
|
|
1164
|
-
description: input.description,
|
|
1165
|
-
type: objectPropertyTypeToSdkPropertyDefinition(input.dataType),
|
|
1166
|
-
nullable: isNullable
|
|
1167
|
-
};
|
|
1168
|
-
case "array": {
|
|
1169
|
-
return {
|
|
1170
|
-
multiplicity: true,
|
|
1171
|
-
description: input.description,
|
|
1172
|
-
type: objectPropertyTypeToSdkPropertyDefinition(input.dataType),
|
|
1173
|
-
nullable: true
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
|
-
default:
|
|
1177
|
-
input.dataType;
|
|
1178
|
-
throw new Error(`Unexpected data type ${JSON.stringify(input.dataType)}`);
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
function objectPropertyTypeToSdkPropertyDefinition(propertyType) {
|
|
1182
|
-
switch (propertyType.type) {
|
|
1183
|
-
case "integer":
|
|
1184
|
-
case "string":
|
|
1185
|
-
case "byte":
|
|
1186
|
-
case "decimal":
|
|
1187
|
-
case "double":
|
|
1188
|
-
case "float":
|
|
1189
|
-
case "long":
|
|
1190
|
-
case "short":
|
|
1191
|
-
case "boolean":
|
|
1192
|
-
case "attachment":
|
|
1193
|
-
case "geopoint":
|
|
1194
|
-
case "geoshape":
|
|
1195
|
-
case "timestamp":
|
|
1196
|
-
case "marking":
|
|
1197
|
-
return propertyType.type;
|
|
1198
|
-
case "date":
|
|
1199
|
-
return "datetime";
|
|
1200
|
-
case "array":
|
|
1201
|
-
return objectPropertyTypeToSdkPropertyDefinition(propertyType.subType);
|
|
1202
|
-
case "timeseries":
|
|
1203
|
-
if (propertyType.itemType.type === "string") {
|
|
1204
|
-
return "stringTimeseries";
|
|
1205
|
-
}
|
|
1206
|
-
return "numericTimeseries";
|
|
1207
|
-
default:
|
|
1208
|
-
throw new Error(`Unexecpected data type ${JSON.stringify(propertyType)}`);
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
// src/shared/wireObjectTypeV2ToSdkObjectDefinition.ts
|
|
1213
|
-
function wireObjectTypeV2ToSdkObjectDefinition(objectTypeWithLink, v2) {
|
|
1214
|
-
if (objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey] === void 0) {
|
|
1215
|
-
throw new Error(`Primary key ${objectTypeWithLink.objectType.primaryKey} not found in ${objectTypeWithLink.objectType.apiName}`);
|
|
1216
|
-
}
|
|
1217
|
-
return {
|
|
1218
|
-
type: "object",
|
|
1219
|
-
apiName: objectTypeWithLink.objectType.apiName,
|
|
1220
|
-
description: objectTypeWithLink.objectType.description,
|
|
1221
|
-
primaryKeyType: wirePropertyV2ToSdkPrimaryKeyTypeDefinition(objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey]),
|
|
1222
|
-
links: Object.fromEntries(objectTypeWithLink.linkTypes.map((linkType) => {
|
|
1223
|
-
return [linkType.apiName, {
|
|
1224
|
-
multiplicity: linkType.cardinality === "MANY",
|
|
1225
|
-
targetType: linkType.objectTypeApiName
|
|
1226
|
-
}];
|
|
1227
|
-
})),
|
|
1228
|
-
properties: Object.fromEntries(Object.entries(objectTypeWithLink.objectType.properties).map(([key, value]) => [key, wirePropertyV2ToSdkPropertyDefinition(value, !(v2 && objectTypeWithLink.objectType.primaryKey === key))]))
|
|
1229
|
-
};
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
// src/shared/wireObjectTypeV2ToSdkObjectConst.ts
|
|
1233
|
-
function wireObjectTypeV2ToSdkObjectConst(object, importExt, v2 = false) {
|
|
1234
|
-
const uniqueLinkTargetTypes = new Set(object.linkTypes.map((a) => a.objectTypeApiName));
|
|
1235
|
-
const definition = wireObjectTypeV2ToSdkObjectDefinition(object, v2);
|
|
1236
|
-
const imports = Array.from(uniqueLinkTargetTypes).filter((type) => type !== definition.apiName).map((type) => `import type { ${type}Def } from "./${type}${importExt}";`);
|
|
1237
|
-
return `
|
|
1238
|
-
${imports.join("\n")}
|
|
1239
|
-
export interface ${object.objectType.apiName}Def extends ObjectTypeDefinition<"${object.objectType.apiName}"> {
|
|
1240
|
-
type: "${definition.type}",
|
|
1241
|
-
apiName: "${definition.apiName}",
|
|
1242
|
-
${definition.description != null ? `description: ${JSON.stringify(definition.description)},` : ""}
|
|
1243
|
-
primaryKeyType: ${JSON.stringify(definition.primaryKeyType)},
|
|
1244
|
-
links: {${Object.entries(definition.links).map(([linkApiName, definition2]) => `${linkApiName}: ObjectTypeLinkDefinition<${definition2.targetType}Def, ${definition2.multiplicity}>`).join(",\n")}
|
|
1245
|
-
},
|
|
1246
|
-
properties: ${JSON.stringify(definition.properties, null, 2)},
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
export const ${object.objectType.apiName}: ${object.objectType.apiName}Def = {
|
|
1250
|
-
type: "${definition.type}",
|
|
1251
|
-
apiName: "${definition.apiName}",
|
|
1252
|
-
${definition.description != null ? `description: ${JSON.stringify(definition.description)},` : ""}
|
|
1253
|
-
primaryKeyType: ${JSON.stringify(definition.primaryKeyType)},
|
|
1254
|
-
links: ${JSON.stringify(definition.links, null, 2)},
|
|
1255
|
-
properties: ${JSON.stringify(definition.properties, null, 2)},
|
|
1256
|
-
};`;
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
// src/v1.1/generatePerObjectInterfaceAndDataFiles.ts
|
|
1260
1162
|
async function generatePerObjectInterfaceAndDataFiles(ontology, fs, outDir, importExt = "") {
|
|
1261
1163
|
await fs.mkdir(outDir, {
|
|
1262
1164
|
recursive: true
|
|
@@ -1264,7 +1166,7 @@ async function generatePerObjectInterfaceAndDataFiles(ontology, fs, outDir, impo
|
|
|
1264
1166
|
await Promise.all(Object.values(ontology.objectTypes).map(async (object) => {
|
|
1265
1167
|
object.linkTypes;
|
|
1266
1168
|
await fs.writeFile(path15__namespace.default.join(outDir, `${object.objectType.apiName}.ts`), await formatTs(`
|
|
1267
|
-
import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from "@osdk/api";
|
|
1169
|
+
import type { ObjectTypeDefinition, ObjectTypeLinkDefinition, PropertyDef } from "@osdk/api";
|
|
1268
1170
|
${wireObjectTypeV2ToObjectInterfaceStringV1(object, importExt)}
|
|
1269
1171
|
|
|
1270
1172
|
${wireObjectTypeV2ToSdkObjectConst(object, importExt)}
|
|
@@ -1539,8 +1441,9 @@ function handleQueryDataType(dataType, importedObjects, isReturnValue) {
|
|
|
1539
1441
|
case "double":
|
|
1540
1442
|
case "float":
|
|
1541
1443
|
case "integer":
|
|
1542
|
-
case "long":
|
|
1543
1444
|
return "number";
|
|
1445
|
+
case "long":
|
|
1446
|
+
return isReturnValue ? "string" : "string | number";
|
|
1544
1447
|
case "date":
|
|
1545
1448
|
return "LocalDate";
|
|
1546
1449
|
case "timestamp":
|
|
@@ -1662,22 +1565,38 @@ async function generateClientSdkVersionOneDotOne(ontology, userAgent, fs, outDir
|
|
|
1662
1565
|
await generateIndexFile(fs, outDir, importExt);
|
|
1663
1566
|
await generateBackCompatDeprecatedExports(fs, outDir, importExt);
|
|
1664
1567
|
}
|
|
1568
|
+
function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceDef, v2 = false) {
|
|
1569
|
+
const definition = deleteUndefineds(generatorConverters.__UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(interfaceDef, v2));
|
|
1570
|
+
const objectDefIdentifier = getObjectDefIdentifier(interfaceDef.apiName, v2);
|
|
1571
|
+
function getV2Types() {
|
|
1572
|
+
return `
|
|
1573
|
+
export interface ${objectDefIdentifier} extends InterfaceDefinition<"${interfaceDef.apiName}", ${interfaceDef.apiName}> {
|
|
1574
|
+
${stringify(definition, {
|
|
1575
|
+
type: () => void 0,
|
|
1576
|
+
apiName: () => void 0,
|
|
1577
|
+
links: (_value) => `{
|
|
1578
|
+
${stringify(definition.links, {
|
|
1579
|
+
"*": (definition2) => `ObjectTypeLinkDefinition<${getObjectDefIdentifier(definition2.targetType, v2)}, ${definition2.multiplicity}>`
|
|
1580
|
+
})}
|
|
1581
|
+
}`,
|
|
1582
|
+
properties: (_value) => `{
|
|
1583
|
+
${stringify(definition.properties, {
|
|
1584
|
+
"*": (propertyDefinition) => `PropertyDef<"${propertyDefinition.type}", "${propertyDefinition.nullable ? "nullable" : "non-nullable"}", "${propertyDefinition.multiplicity ? "array" : "single"}">`
|
|
1585
|
+
})}
|
|
1586
|
+
}`
|
|
1587
|
+
})}
|
|
1588
|
+
}
|
|
1665
1589
|
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
properties: Object.fromEntries(Object.entries(interfaceType.properties).map(([key, value]) => {
|
|
1677
|
-
return [key, wirePropertyV2ToSdkPropertyDefinition(value, true)];
|
|
1678
|
-
})),
|
|
1679
|
-
links: {}
|
|
1680
|
-
};
|
|
1590
|
+
`;
|
|
1591
|
+
}
|
|
1592
|
+
const imports = [];
|
|
1593
|
+
return `${imports.join("\n")}
|
|
1594
|
+
|
|
1595
|
+
${v2 ? getV2Types() : ""}
|
|
1596
|
+
|
|
1597
|
+
export const ${definition.apiName}: ${objectDefIdentifier} = {
|
|
1598
|
+
${stringify(definition)}
|
|
1599
|
+
};`;
|
|
1681
1600
|
}
|
|
1682
1601
|
async function generateOntologyMetadataFile(ontology, userAgent, fs, outDir) {
|
|
1683
1602
|
fs.writeFile(path15__namespace.default.join(outDir, "OntologyMetadata.ts"), await formatTs(`
|
|
@@ -1693,15 +1612,19 @@ async function generateOntologyMetadataFile(ontology, userAgent, fs, outDir) {
|
|
|
1693
1612
|
async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs, outDir, packageType = "commonjs") {
|
|
1694
1613
|
await verifyOutdir(outDir, fs);
|
|
1695
1614
|
const sanitizedOntology = sanitizeMetadata(ontology);
|
|
1696
|
-
const objectNames = Object.keys(sanitizedOntology.objectTypes);
|
|
1697
|
-
const actionNames = Object.keys(sanitizedOntology.actionTypes);
|
|
1698
|
-
|
|
1615
|
+
const objectNames = Object.keys(sanitizedOntology.objectTypes).sort((a, b) => a.localeCompare(b));
|
|
1616
|
+
const actionNames = Object.keys(sanitizedOntology.actionTypes).sort((a, b) => a.localeCompare(b));
|
|
1617
|
+
Object.keys(sanitizedOntology.queryTypes).sort((a, b) => a.localeCompare(b));
|
|
1618
|
+
const interfaceNames = Object.keys(sanitizedOntology.interfaceTypes ?? {}).sort((a, b) => a.localeCompare(b));
|
|
1699
1619
|
const importExt = packageType === "module" ? ".js" : "";
|
|
1700
1620
|
await fs.mkdir(outDir, {
|
|
1701
1621
|
recursive: true
|
|
1702
1622
|
});
|
|
1703
1623
|
fs.writeFile(path15__namespace.default.join(outDir, "index.ts"), await formatTs(`
|
|
1704
1624
|
export { Ontology } from "./Ontology${importExt}";
|
|
1625
|
+
export * from "./ontology/actions/index${importExt}";
|
|
1626
|
+
export * from "./ontology/objects${importExt}";
|
|
1627
|
+
export * from "./ontology/interfaces${importExt}";
|
|
1705
1628
|
`));
|
|
1706
1629
|
await generateOntologyMetadataFile(sanitizedOntology, userAgent, fs, outDir);
|
|
1707
1630
|
await fs.writeFile(path15__namespace.default.join(outDir, "Ontology.ts"), await formatTs(`
|
|
@@ -1745,18 +1668,11 @@ async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs, out
|
|
|
1745
1668
|
for (const name of objectNames) {
|
|
1746
1669
|
const obj = ontology.objectTypes[name];
|
|
1747
1670
|
await fs.writeFile(path15__namespace.default.join(outDir, "ontology", `objects`, `${name}.ts`), await formatTs(`
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
${wireObjectTypeV2ToSdkObjectConst(obj, importExt, true)}
|
|
1671
|
+
import type { ObjectTypeDefinition, ObjectTypeLinkDefinition, PropertyDef } from "@osdk/api";
|
|
1672
|
+
import { Osdk } from "@osdk/client";
|
|
1752
1673
|
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
// obj,
|
|
1756
|
-
// )
|
|
1757
|
-
*/
|
|
1758
|
-
""}
|
|
1759
|
-
`));
|
|
1674
|
+
${wireObjectTypeV2ToSdkObjectConst(obj, importExt, true)}
|
|
1675
|
+
`));
|
|
1760
1676
|
}
|
|
1761
1677
|
await generateOntologyInterfaces(fs, outDir, interfaceNames, ontology, importExt);
|
|
1762
1678
|
const actionsDir = path15__namespace.default.join(outDir, "ontology", "actions");
|
|
@@ -1765,7 +1681,8 @@ async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs, out
|
|
|
1765
1681
|
});
|
|
1766
1682
|
await generatePerActionDataFiles(sanitizedOntology, fs, actionsDir, importExt, true);
|
|
1767
1683
|
await fs.writeFile(path15__namespace.default.join(outDir, "ontology", "objects.ts"), await formatTs(`
|
|
1768
|
-
${Object.keys(ontology.objectTypes).map((apiName) => `export * from "./objects/${apiName}${importExt}";`).join("\n")}
|
|
1684
|
+
${Object.keys(ontology.objectTypes).sort((a, b) => a.localeCompare(b)).map((apiName) => `export * from "./objects/${apiName}${importExt}";`).join("\n")}
|
|
1685
|
+
${Object.keys(ontology.objectTypes).length === 0 ? "export {};" : ""}
|
|
1769
1686
|
`));
|
|
1770
1687
|
}
|
|
1771
1688
|
function stringUnionFrom2(values) {
|
|
@@ -1784,13 +1701,14 @@ async function generateOntologyInterfaces(fs, outDir, interfaceNames, ontology,
|
|
|
1784
1701
|
const obj = ontology.interfaceTypes[name];
|
|
1785
1702
|
await fs.writeFile(path15__namespace.default.join(interfacesDir, `${name}.ts`), await formatTs(`
|
|
1786
1703
|
|
|
1787
|
-
import type { InterfaceDefinition } from "@osdk/api";
|
|
1704
|
+
import type { InterfaceDefinition, PropertyDef } from "@osdk/api";
|
|
1788
1705
|
|
|
1789
1706
|
${__UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(obj, true)}
|
|
1790
1707
|
`));
|
|
1791
1708
|
}
|
|
1792
1709
|
await fs.writeFile(interfacesDir + ".ts", await formatTs(`
|
|
1793
1710
|
${Object.keys(ontology.interfaceTypes ?? {}).map((apiName) => `export * from "./interfaces/${apiName}${importExt}";`).join("\n")}
|
|
1711
|
+
${Object.keys(ontology.interfaceTypes ?? {}).length === 0 ? "export {}" : ""}
|
|
1794
1712
|
`));
|
|
1795
1713
|
}
|
|
1796
1714
|
|