@osdk/generator 1.6.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 +50 -25
- package/build/js/index.cjs.map +1 -1
- package/build/js/index.mjs +51 -26
- package/build/js/index.mjs.map +1 -1
- package/build/types/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.d.ts +1 -1
- package/build/types/util/test/TodoWireOntology.d.ts +2 -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 -5
package/build/js/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import * as path15 from 'path';
|
|
|
2
2
|
import path15__default, { join } from 'path';
|
|
3
3
|
import { format } from 'prettier';
|
|
4
4
|
import organizeImports from 'prettier-plugin-organize-imports';
|
|
5
|
-
import { wireObjectTypeFullMetadataToSdkObjectTypeDefinition,
|
|
5
|
+
import { wireObjectTypeFullMetadataToSdkObjectTypeDefinition, __UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition } from '@osdk/generator-converters';
|
|
6
6
|
|
|
7
7
|
// src/v1.1/generateClientSdkVersionOneDotOne.ts
|
|
8
8
|
|
|
@@ -848,7 +848,9 @@ var defaultCustomizer = (value, defaultValueFormatter, key, defaultKeyFormatter)
|
|
|
848
848
|
function stringify(obj, customizer = {}, separator = ",\n") {
|
|
849
849
|
const defaultKeyFormatter = (key) => `${JSON.stringify(key)}`;
|
|
850
850
|
const entries = [];
|
|
851
|
-
|
|
851
|
+
const sortedKeys = Object.keys(obj).sort((a, b) => a.localeCompare(b));
|
|
852
|
+
for (const key of sortedKeys) {
|
|
853
|
+
const value = obj[key];
|
|
852
854
|
const res = (customizer[key] ?? customizer["*"] ?? defaultCustomizer)(value, (value2) => JSON.stringify(value2, null, 2), key, defaultKeyFormatter);
|
|
853
855
|
if (res) {
|
|
854
856
|
if (typeof res === "string") {
|
|
@@ -962,7 +964,7 @@ function wirePropertyTypeV2ToTypeScriptType(property) {
|
|
|
962
964
|
case "date":
|
|
963
965
|
return "LocalDate";
|
|
964
966
|
case "decimal":
|
|
965
|
-
return "
|
|
967
|
+
return "string";
|
|
966
968
|
case "double":
|
|
967
969
|
return "number";
|
|
968
970
|
case "float":
|
|
@@ -972,7 +974,7 @@ function wirePropertyTypeV2ToTypeScriptType(property) {
|
|
|
972
974
|
case "geoshape":
|
|
973
975
|
return "GeoShape";
|
|
974
976
|
case "long":
|
|
975
|
-
return "
|
|
977
|
+
return "string";
|
|
976
978
|
case "short":
|
|
977
979
|
return "number";
|
|
978
980
|
case "timestamp":
|
|
@@ -1012,13 +1014,14 @@ async function generatePerActionDataFiles(ontology, fs, outDir, importExt, v2) {
|
|
|
1012
1014
|
const paramsIdentifier = `${action.apiName}$Params`;
|
|
1013
1015
|
function createParamsDef() {
|
|
1014
1016
|
const entries = Object.entries(parameters);
|
|
1017
|
+
entries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
1015
1018
|
if (entries.length === 0) {
|
|
1016
1019
|
return `// Represents the definition of the parameters for the action
|
|
1017
1020
|
export type ${paramsDefIdentifier} = Record<string, never>;`;
|
|
1018
1021
|
}
|
|
1019
1022
|
return `// Represents the definition of the parameters for the action
|
|
1020
1023
|
export type ${paramsDefIdentifier} = {
|
|
1021
|
-
${
|
|
1024
|
+
${entries.map(([key, value]) => {
|
|
1022
1025
|
return `"${key}": {
|
|
1023
1026
|
${stringify(value, {
|
|
1024
1027
|
description: (value2, d) => value2 ? d(value2) : void 0,
|
|
@@ -1057,7 +1060,7 @@ async function generatePerActionDataFiles(ontology, fs, outDir, importExt, v2) {
|
|
|
1057
1060
|
|
|
1058
1061
|
// Represents the definition of the action
|
|
1059
1062
|
export interface ${actionDefIdentifier} extends ActionDefinition<"${action.apiName}", ${uniqueApiNamesString}, ${action.apiName}>{
|
|
1060
|
-
${Object.entries(actionDefSansParameters).map(([key, value]) => {
|
|
1063
|
+
${Object.entries(actionDefSansParameters).sort((a, b) => a[0].localeCompare(b[0])).map(([key, value]) => {
|
|
1061
1064
|
return `${key}: ${JSON.stringify(value)};`;
|
|
1062
1065
|
}).join("\n")}
|
|
1063
1066
|
parameters: ${paramsDefIdentifier}
|
|
@@ -1090,6 +1093,7 @@ async function generatePerActionDataFiles(ontology, fs, outDir, importExt, v2) {
|
|
|
1090
1093
|
}));
|
|
1091
1094
|
await fs.writeFile(path15__default.join(outDir, `index.ts`), await formatTs(`
|
|
1092
1095
|
${Object.values(ontology.actionTypes).map((action) => `export {${action.apiName}} from "./${action.apiName}${importExt}";`).join("\n")}
|
|
1096
|
+
${Object.keys(ontology.actionTypes).length === 0 ? "export {};" : ""}
|
|
1093
1097
|
`));
|
|
1094
1098
|
}
|
|
1095
1099
|
function extractReferencedObjectsFromAction(actionType) {
|
|
@@ -1413,8 +1417,9 @@ function handleQueryDataType(dataType, importedObjects, isReturnValue) {
|
|
|
1413
1417
|
case "double":
|
|
1414
1418
|
case "float":
|
|
1415
1419
|
case "integer":
|
|
1416
|
-
case "long":
|
|
1417
1420
|
return "number";
|
|
1421
|
+
case "long":
|
|
1422
|
+
return isReturnValue ? "string" : "string | number";
|
|
1418
1423
|
case "date":
|
|
1419
1424
|
return "LocalDate";
|
|
1420
1425
|
case "timestamp":
|
|
@@ -1536,20 +1541,38 @@ async function generateClientSdkVersionOneDotOne(ontology, userAgent, fs, outDir
|
|
|
1536
1541
|
await generateIndexFile(fs, outDir, importExt);
|
|
1537
1542
|
await generateBackCompatDeprecatedExports(fs, outDir, importExt);
|
|
1538
1543
|
}
|
|
1539
|
-
function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1544
|
+
function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceDef, v2 = false) {
|
|
1545
|
+
const definition = deleteUndefineds(__UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(interfaceDef, v2));
|
|
1546
|
+
const objectDefIdentifier = getObjectDefIdentifier(interfaceDef.apiName, v2);
|
|
1547
|
+
function getV2Types() {
|
|
1548
|
+
return `
|
|
1549
|
+
export interface ${objectDefIdentifier} extends InterfaceDefinition<"${interfaceDef.apiName}", ${interfaceDef.apiName}> {
|
|
1550
|
+
${stringify(definition, {
|
|
1551
|
+
type: () => void 0,
|
|
1552
|
+
apiName: () => void 0,
|
|
1553
|
+
links: (_value) => `{
|
|
1554
|
+
${stringify(definition.links, {
|
|
1555
|
+
"*": (definition2) => `ObjectTypeLinkDefinition<${getObjectDefIdentifier(definition2.targetType, v2)}, ${definition2.multiplicity}>`
|
|
1556
|
+
})}
|
|
1557
|
+
}`,
|
|
1558
|
+
properties: (_value) => `{
|
|
1559
|
+
${stringify(definition.properties, {
|
|
1560
|
+
"*": (propertyDefinition) => `PropertyDef<"${propertyDefinition.type}", "${propertyDefinition.nullable ? "nullable" : "non-nullable"}", "${propertyDefinition.multiplicity ? "array" : "single"}">`
|
|
1561
|
+
})}
|
|
1562
|
+
}`
|
|
1563
|
+
})}
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
`;
|
|
1567
|
+
}
|
|
1568
|
+
const imports = [];
|
|
1569
|
+
return `${imports.join("\n")}
|
|
1570
|
+
|
|
1571
|
+
${v2 ? getV2Types() : ""}
|
|
1572
|
+
|
|
1573
|
+
export const ${definition.apiName}: ${objectDefIdentifier} = {
|
|
1574
|
+
${stringify(definition)}
|
|
1575
|
+
};`;
|
|
1553
1576
|
}
|
|
1554
1577
|
async function generateOntologyMetadataFile(ontology, userAgent, fs, outDir) {
|
|
1555
1578
|
fs.writeFile(path15__default.join(outDir, "OntologyMetadata.ts"), await formatTs(`
|
|
@@ -1565,9 +1588,10 @@ async function generateOntologyMetadataFile(ontology, userAgent, fs, outDir) {
|
|
|
1565
1588
|
async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs, outDir, packageType = "commonjs") {
|
|
1566
1589
|
await verifyOutdir(outDir, fs);
|
|
1567
1590
|
const sanitizedOntology = sanitizeMetadata(ontology);
|
|
1568
|
-
const objectNames = Object.keys(sanitizedOntology.objectTypes);
|
|
1569
|
-
const actionNames = Object.keys(sanitizedOntology.actionTypes);
|
|
1570
|
-
|
|
1591
|
+
const objectNames = Object.keys(sanitizedOntology.objectTypes).sort((a, b) => a.localeCompare(b));
|
|
1592
|
+
const actionNames = Object.keys(sanitizedOntology.actionTypes).sort((a, b) => a.localeCompare(b));
|
|
1593
|
+
Object.keys(sanitizedOntology.queryTypes).sort((a, b) => a.localeCompare(b));
|
|
1594
|
+
const interfaceNames = Object.keys(sanitizedOntology.interfaceTypes ?? {}).sort((a, b) => a.localeCompare(b));
|
|
1571
1595
|
const importExt = packageType === "module" ? ".js" : "";
|
|
1572
1596
|
await fs.mkdir(outDir, {
|
|
1573
1597
|
recursive: true
|
|
@@ -1633,7 +1657,8 @@ async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs, out
|
|
|
1633
1657
|
});
|
|
1634
1658
|
await generatePerActionDataFiles(sanitizedOntology, fs, actionsDir, importExt, true);
|
|
1635
1659
|
await fs.writeFile(path15__default.join(outDir, "ontology", "objects.ts"), await formatTs(`
|
|
1636
|
-
${Object.keys(ontology.objectTypes).map((apiName) => `export * from "./objects/${apiName}${importExt}";`).join("\n")}
|
|
1660
|
+
${Object.keys(ontology.objectTypes).sort((a, b) => a.localeCompare(b)).map((apiName) => `export * from "./objects/${apiName}${importExt}";`).join("\n")}
|
|
1661
|
+
${Object.keys(ontology.objectTypes).length === 0 ? "export {};" : ""}
|
|
1637
1662
|
`));
|
|
1638
1663
|
}
|
|
1639
1664
|
function stringUnionFrom2(values) {
|
|
@@ -1652,7 +1677,7 @@ async function generateOntologyInterfaces(fs, outDir, interfaceNames, ontology,
|
|
|
1652
1677
|
const obj = ontology.interfaceTypes[name];
|
|
1653
1678
|
await fs.writeFile(path15__default.join(interfacesDir, `${name}.ts`), await formatTs(`
|
|
1654
1679
|
|
|
1655
|
-
import type { InterfaceDefinition } from "@osdk/api";
|
|
1680
|
+
import type { InterfaceDefinition, PropertyDef } from "@osdk/api";
|
|
1656
1681
|
|
|
1657
1682
|
${__UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(obj, true)}
|
|
1658
1683
|
`));
|