@osdk/generator 1.3.0 → 1.4.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 +273 -94
- package/build/js/index.cjs.map +1 -1
- package/build/js/index.mjs +273 -94
- package/build/js/index.mjs.map +1 -1
- package/build/types/shared/wireObjectTypeV2ToSdkObjectConst.d.ts +2 -2
- package/build/types/shared/wireObjectTypeV2ToSdkObjectDefinition.d.ts +2 -2
- package/build/types/util/deleteUndefineds.d.ts +1 -0
- package/build/types/util/test/TodoWireOntology.d.ts +4 -0
- package/build/types/v1.1/generateActions.d.ts +2 -0
- package/build/types/v1.1/generateBulkActions.d.ts +3 -0
- package/build/types/v1.1/generateBulkActions.test.d.ts +1 -0
- package/build/types/v1.1/generatePerActionDataFiles.d.ts +1 -1
- package/build/types/v1.1/wireObjectTypeV2ToV1ObjectInterfaceString.d.ts +3 -2
- package/changelog/1.2.0/pr-10.v2.yml +5 -0
- package/changelog/1.3.0/pr-20.v2.yml +5 -0
- package/changelog/1.4.0/pr-34.v2.yml +5 -0
- package/changelog/1.4.0/pr-48.v2.yml +5 -0
- package/changelog/1.4.0/pr-53.v2.yml +5 -0
- package/changelog/1.4.0/pr-65.v2.yml +5 -0
- package/changelog/@unreleased/.gitkeep +0 -0
- package/package.json +9 -4
- /package/{CHANGELOG.md → CHANGELOG_OLD.md} +0 -0
package/build/js/index.cjs
CHANGED
|
@@ -163,6 +163,8 @@ function getTypeScriptTypeFromDataType(actionParameter, importedObjects) {
|
|
|
163
163
|
return `number`;
|
|
164
164
|
case "timestamp":
|
|
165
165
|
return `Timestamp`;
|
|
166
|
+
case "marking":
|
|
167
|
+
return "string";
|
|
166
168
|
default:
|
|
167
169
|
throw new Error(`Unsupported action parameter type: ${actionParameter}`);
|
|
168
170
|
}
|
|
@@ -557,6 +559,54 @@ async function generateBackCompatDeprecatedExports(fs, outDir, importExt = "") {
|
|
|
557
559
|
await generateOntologyRuntimeDistDir(outDir, fs, importExt);
|
|
558
560
|
await generateOAuthClientDistDir(outDir, fs, importExt);
|
|
559
561
|
}
|
|
562
|
+
async function generateBulkActions(ontology, fs, outDir, importExt = "") {
|
|
563
|
+
const importedObjects = /* @__PURE__ */ new Set();
|
|
564
|
+
let actionSignatures = [];
|
|
565
|
+
for (const action of Object.values(ontology.actionTypes)) {
|
|
566
|
+
const entries = Object.entries(action.parameters);
|
|
567
|
+
const modifiedEntityTypes = getModifiedEntityTypes(action);
|
|
568
|
+
const addedObjects = Array.from(modifiedEntityTypes.addedObjects);
|
|
569
|
+
const modifiedObjects = Array.from(modifiedEntityTypes.modifiedObjects);
|
|
570
|
+
addedObjects.forEach(importedObjects.add, importedObjects);
|
|
571
|
+
modifiedObjects.forEach(importedObjects.add, importedObjects);
|
|
572
|
+
let jsDocBlock = ["/**"];
|
|
573
|
+
if (action.description) {
|
|
574
|
+
jsDocBlock.push(`* ${action.description}`);
|
|
575
|
+
}
|
|
576
|
+
let parameterBlock = "";
|
|
577
|
+
if (entries.length > 0) {
|
|
578
|
+
parameterBlock = `params: {
|
|
579
|
+
`;
|
|
580
|
+
for (const [parameterName, parameterData] of entries) {
|
|
581
|
+
parameterBlock += `"${parameterName}"`;
|
|
582
|
+
parameterBlock += parameterData.required ? ": " : "?: ";
|
|
583
|
+
const typeScriptType = getTypeScriptTypeFromDataType(parameterData.dataType, importedObjects);
|
|
584
|
+
parameterBlock += `${typeScriptType};
|
|
585
|
+
`;
|
|
586
|
+
jsDocBlock.push(`* @param {${typeScriptType}} params.${parameterName}`);
|
|
587
|
+
}
|
|
588
|
+
parameterBlock += "}[], ";
|
|
589
|
+
} else {
|
|
590
|
+
parameterBlock = `params: Record<string,never>[], `;
|
|
591
|
+
}
|
|
592
|
+
jsDocBlock.push(`*/`);
|
|
593
|
+
actionSignatures.push(`
|
|
594
|
+
${jsDocBlock.join("\n")}
|
|
595
|
+
${action.apiName}<O extends BulkActionExecutionOptions>(${parameterBlock}options?: O):
|
|
596
|
+
Promise<Result<BulkActionResponseFromOptions<O, Edits<${addedObjects.length > 0 ? addedObjects.join(" | ") : "void"}, ${modifiedObjects.length > 0 ? modifiedObjects.join(" | ") : "void"}>>, ActionError>>;
|
|
597
|
+
`);
|
|
598
|
+
}
|
|
599
|
+
await fs.mkdir(outDir, {
|
|
600
|
+
recursive: true
|
|
601
|
+
});
|
|
602
|
+
await fs.writeFile(path15__namespace.default.join(outDir, "BulkActions.ts"), await formatTs(`
|
|
603
|
+
import type { ObjectSet, LocalDate, Timestamp, Attachment, Edits, ActionExecutionOptions, BulkActionExecutionOptions, ActionError, Result, ActionResponseFromOptions, BulkActionResponseFromOptions } from "@osdk/legacy-client";
|
|
604
|
+
${Array.from(importedObjects).map((importedObject) => `import type { ${importedObject} } from "../objects/${importedObject}${importExt}";`).join("\n")}
|
|
605
|
+
export interface BulkActions {
|
|
606
|
+
${actionSignatures.join("\n")}
|
|
607
|
+
}
|
|
608
|
+
`));
|
|
609
|
+
}
|
|
560
610
|
async function generateFoundryClientFile(fs, outDir, importExt = "") {
|
|
561
611
|
await fs.writeFile(path15__namespace.default.join(outDir, "FoundryClient.ts"), await formatTs(`
|
|
562
612
|
import { BaseFoundryClient } from "@osdk/legacy-client";
|
|
@@ -634,6 +684,7 @@ async function generateMetadataFile(ontology, userAgent, fs, outDir, importExt =
|
|
|
634
684
|
import type { Objects } from "./ontology/objects/Objects${importExt}";
|
|
635
685
|
import type { Actions } from "./ontology/actions/Actions${importExt}";
|
|
636
686
|
import type { Queries } from "./ontology/queries/Queries${importExt}";
|
|
687
|
+
import type { BulkActions } from "./ontology/actions/BulkActions${importExt}";
|
|
637
688
|
${objectNames.map((name) => `import {${name}} from "./ontology/objects/${name}${importExt}";`).join("\n")}
|
|
638
689
|
${actionNames.map((name) => `import {${getImportClause(name, actionAltNames)}} from "./ontology/actions/${name}${importExt}";`).join("\n")}
|
|
639
690
|
${queryNames.map((name) => `import {${getImportClause(name, queryAltNames)}} from "./ontology/queries/${name}${importExt}";`).join("\n")}
|
|
@@ -676,6 +727,7 @@ async function generateMetadataFile(ontology, userAgent, fs, outDir, importExt =
|
|
|
676
727
|
export interface Ontology extends ClientOntology<typeof Ontology> {
|
|
677
728
|
objects: Objects;
|
|
678
729
|
actions: Actions;
|
|
730
|
+
bulkActions: BulkActions;
|
|
679
731
|
queries: Queries;
|
|
680
732
|
}`));
|
|
681
733
|
}
|
|
@@ -743,6 +795,7 @@ async function generateOntologyIndexFile(fs, outDir) {
|
|
|
743
795
|
function wireActionTypeV2ToSdkActionDefinition(input) {
|
|
744
796
|
const modifiedEntityTypes = getModifiedEntityTypes(input);
|
|
745
797
|
return {
|
|
798
|
+
type: "action",
|
|
746
799
|
apiName: input.apiName,
|
|
747
800
|
parameters: Object.fromEntries(Object.entries(input.parameters).map(([key, value]) => [key, wireActionParameterV2ToSdkParameterDefinition(value)])),
|
|
748
801
|
displayName: input.displayName,
|
|
@@ -762,6 +815,7 @@ function wireActionParameterV2ToSdkParameterDefinition(value) {
|
|
|
762
815
|
case "long":
|
|
763
816
|
case "objectSet":
|
|
764
817
|
case "timestamp":
|
|
818
|
+
case "marking":
|
|
765
819
|
return {
|
|
766
820
|
multiplicity: false,
|
|
767
821
|
type: actionPropertyToSdkPropertyDefinition(value.dataType),
|
|
@@ -771,7 +825,7 @@ function wireActionParameterV2ToSdkParameterDefinition(value) {
|
|
|
771
825
|
case "array":
|
|
772
826
|
return {
|
|
773
827
|
multiplicity: true,
|
|
774
|
-
type: actionPropertyToSdkPropertyDefinition(value.dataType),
|
|
828
|
+
type: actionPropertyToSdkPropertyDefinition(value.dataType.subType),
|
|
775
829
|
nullable: value.required ? false : true,
|
|
776
830
|
description: value.description
|
|
777
831
|
};
|
|
@@ -786,6 +840,7 @@ function actionPropertyToSdkPropertyDefinition(parameterType) {
|
|
|
786
840
|
case "integer":
|
|
787
841
|
case "long":
|
|
788
842
|
case "timestamp":
|
|
843
|
+
case "marking":
|
|
789
844
|
return parameterType.type;
|
|
790
845
|
case "date":
|
|
791
846
|
return "datetime";
|
|
@@ -824,20 +879,192 @@ function createModifiedEntities(addedObjects, modifiedObjects) {
|
|
|
824
879
|
return entities;
|
|
825
880
|
}
|
|
826
881
|
|
|
882
|
+
// src/util/deleteUndefineds.ts
|
|
883
|
+
function deleteUndefineds(obj) {
|
|
884
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== void 0));
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// src/util/reservedKeywords.ts
|
|
888
|
+
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
|
+
function isReservedKeyword(name) {
|
|
890
|
+
return reservedKeywords.has(name);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
// src/v1.1/wireObjectTypeV2ToV1ObjectInterfaceString.ts
|
|
894
|
+
function wireObjectTypeV2ToObjectInterfaceStringV1(objectTypeWithLinks, importExt = "") {
|
|
895
|
+
const uniqueLinkTargets = new Set(objectTypeWithLinks.linkTypes.map((a) => a.objectTypeApiName).filter((a) => a !== objectTypeWithLinks.objectType.apiName));
|
|
896
|
+
return `import type { OntologyObject, LocalDate, Timestamp, GeoShape, GeoPoint, Attachment, TimeSeries, MultiLink, SingleLink } from "@osdk/legacy-client";
|
|
897
|
+
${Array.from(uniqueLinkTargets).map((linkTarget) => `import type { ${linkTarget} } from "./${linkTarget}${importExt}";`).join("\n")}
|
|
898
|
+
|
|
899
|
+
${getDescriptionIfPresent(objectTypeWithLinks.objectType.description)}
|
|
900
|
+
export interface ${objectTypeWithLinks.objectType.apiName} extends OntologyObject {
|
|
901
|
+
readonly __apiName: "${objectTypeWithLinks.objectType.apiName}";
|
|
902
|
+
readonly __primaryKey: ${wirePropertyTypeV2ToTypeScriptType(objectTypeWithLinks.objectType.properties[objectTypeWithLinks.objectType.primaryKey].dataType)};
|
|
903
|
+
${Object.entries(objectTypeWithLinks.objectType.properties).sort((a, b) => a[0].localeCompare(b[0])).flatMap(([propertyName, propertyDefinition]) => {
|
|
904
|
+
const propertyType = wirePropertyTypeV2ToTypeScriptType(propertyDefinition.dataType);
|
|
905
|
+
const entries = [`${getDescriptionIfPresent(propertyDefinition.description, true)}readonly ${propertyName}: ${propertyType} | undefined`];
|
|
906
|
+
if (isReservedKeyword(propertyName)) {
|
|
907
|
+
entries.push(`/** @deprecated please migrate to '${propertyName}' instead */
|
|
908
|
+
readonly ${propertyName}_: ${propertyType} | undefined`);
|
|
909
|
+
}
|
|
910
|
+
return entries;
|
|
911
|
+
}).join(";\n")}
|
|
912
|
+
${objectTypeWithLinks.linkTypes.flatMap((linkType) => {
|
|
913
|
+
const entries = [`readonly ${linkType.apiName}: ${linkType.cardinality === "MANY" ? "MultiLink" : "SingleLink"}<${linkType.objectTypeApiName}>`];
|
|
914
|
+
return entries;
|
|
915
|
+
}).join(";\n")}
|
|
916
|
+
}
|
|
917
|
+
`;
|
|
918
|
+
}
|
|
919
|
+
function wirePropertyTypeV2ToTypeScriptType(property) {
|
|
920
|
+
switch (property.type) {
|
|
921
|
+
case "string":
|
|
922
|
+
return "string";
|
|
923
|
+
case "boolean":
|
|
924
|
+
return "boolean";
|
|
925
|
+
case "array":
|
|
926
|
+
return wirePropertyTypeV2ToTypeScriptType(property.subType) + "[]";
|
|
927
|
+
case "integer":
|
|
928
|
+
return "number";
|
|
929
|
+
case "attachment":
|
|
930
|
+
return "Attachment";
|
|
931
|
+
case "byte":
|
|
932
|
+
return "number";
|
|
933
|
+
case "date":
|
|
934
|
+
return "LocalDate";
|
|
935
|
+
case "decimal":
|
|
936
|
+
return "number";
|
|
937
|
+
case "double":
|
|
938
|
+
return "number";
|
|
939
|
+
case "float":
|
|
940
|
+
return "number";
|
|
941
|
+
case "geopoint":
|
|
942
|
+
return "GeoPoint";
|
|
943
|
+
case "geoshape":
|
|
944
|
+
return "GeoShape";
|
|
945
|
+
case "long":
|
|
946
|
+
return "number";
|
|
947
|
+
case "short":
|
|
948
|
+
return "number";
|
|
949
|
+
case "timestamp":
|
|
950
|
+
return "Timestamp";
|
|
951
|
+
case "timeseries":
|
|
952
|
+
return property.itemType.type === "string" ? `TimeSeries<string>` : `TimeSeries<number>`;
|
|
953
|
+
case "marking":
|
|
954
|
+
return "string";
|
|
955
|
+
default:
|
|
956
|
+
throw new Error(`Unknown property type ${property}`);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
function getDescriptionIfPresent(description, includeNewline) {
|
|
960
|
+
if (description) {
|
|
961
|
+
return `/**
|
|
962
|
+
* ${description}
|
|
963
|
+
*/${includeNewline ? "\n" : ""}`;
|
|
964
|
+
}
|
|
965
|
+
return "";
|
|
966
|
+
}
|
|
967
|
+
|
|
827
968
|
// src/v1.1/generatePerActionDataFiles.ts
|
|
828
|
-
|
|
969
|
+
function stringifyWithoutOuterBraces(obj) {
|
|
970
|
+
return JSON.stringify(obj, null, 2).replace(/^\{\n/, "").replace(/\n\}$/, "");
|
|
971
|
+
}
|
|
972
|
+
async function generatePerActionDataFiles(ontology, fs, outDir, importExt, v2) {
|
|
829
973
|
await fs.mkdir(outDir, {
|
|
830
974
|
recursive: true
|
|
831
975
|
});
|
|
832
976
|
await Promise.all(Object.values(ontology.actionTypes).map(async (action) => {
|
|
833
977
|
const uniqueApiNames = new Set(extractReferencedObjectsFromAction(action));
|
|
978
|
+
const uniqueApiNamesString = uniqueApiNames.size > 0 ? [...uniqueApiNames].map((apiName) => `"${apiName}"`).join("|") : "never";
|
|
979
|
+
const fullActionDef = deleteUndefineds(wireActionTypeV2ToSdkActionDefinition(action));
|
|
980
|
+
const {
|
|
981
|
+
parameters,
|
|
982
|
+
...actionDefSansParameters
|
|
983
|
+
} = fullActionDef;
|
|
984
|
+
const actionDefIdentifier = `ActionDef$${action.apiName}`;
|
|
985
|
+
const paramsDefIdentifier = `${actionDefIdentifier}$Params`;
|
|
986
|
+
const paramsIdentifier = `${action.apiName}$Params`;
|
|
987
|
+
function createParamsDef() {
|
|
988
|
+
const entries = Object.entries(parameters);
|
|
989
|
+
if (entries.length === 0) {
|
|
990
|
+
return `// Represents the definition of the parameters for the action
|
|
991
|
+
export type ${paramsDefIdentifier} = Record<string, never>;`;
|
|
992
|
+
}
|
|
993
|
+
return `// Represents the definition of the parameters for the action
|
|
994
|
+
export type ${paramsDefIdentifier} = {
|
|
995
|
+
${Object.entries(parameters).map(([key, value]) => {
|
|
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
|
+
}
|
|
1008
|
+
return `"${key}": {
|
|
1009
|
+
type: ${q};
|
|
1010
|
+
${stringifyWithoutOuterBraces(remain)}
|
|
1011
|
+
}
|
|
1012
|
+
`;
|
|
1013
|
+
}).join(";\n")}
|
|
1014
|
+
}`;
|
|
1015
|
+
}
|
|
1016
|
+
function createV2Types() {
|
|
1017
|
+
return `
|
|
1018
|
+
|
|
1019
|
+
${createParamsDef()}
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
// Represents the runtime arguments for the action
|
|
1023
|
+
export type ${paramsIdentifier} = NOOP<OsdkActionParameters<${paramsDefIdentifier}>>;
|
|
1024
|
+
|
|
1025
|
+
|
|
1026
|
+
// Represents a fqn of the action
|
|
1027
|
+
export interface ${action.apiName} {
|
|
1028
|
+
${getDescriptionIfPresent(action.description)}
|
|
1029
|
+
<OP extends ApplyActionOptions>(args: ${paramsIdentifier}, options?: OP): Promise<ActionReturnTypeForOptions<OP>>;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
// Represents the definition of the action
|
|
1034
|
+
export interface ${actionDefIdentifier} extends ActionDefinition<"${action.apiName}", ${uniqueApiNamesString}, ${action.apiName}>{
|
|
1035
|
+
${Object.entries(actionDefSansParameters).map(([key, value]) => {
|
|
1036
|
+
return `${key}: ${JSON.stringify(value)};`;
|
|
1037
|
+
}).join("\n")}
|
|
1038
|
+
parameters: ${paramsDefIdentifier}
|
|
1039
|
+
}`;
|
|
1040
|
+
}
|
|
1041
|
+
function createV2Object() {
|
|
1042
|
+
return ` export const ${action.apiName}: ${actionDefIdentifier} = ${JSON.stringify(fullActionDef, null, 2)} `;
|
|
1043
|
+
}
|
|
1044
|
+
function createV1Object() {
|
|
1045
|
+
return ` export const ${action.apiName} = ${JSON.stringify(fullActionDef, null, 2)} satisfies ActionDefinition<"${action.apiName}", ${uniqueApiNamesString}>;`;
|
|
1046
|
+
}
|
|
1047
|
+
const referencedObjectDefs = /* @__PURE__ */ new Set();
|
|
1048
|
+
for (const p of Object.values(action.parameters)) {
|
|
1049
|
+
if (p.dataType.type === "object" || p.dataType.type === "objectSet") {
|
|
1050
|
+
referencedObjectDefs.add(p.dataType.objectApiName + "Def");
|
|
1051
|
+
referencedObjectDefs.add(p.dataType.objectTypeApiName + "Def");
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
const importObjects = referencedObjectDefs.size > 0 ? `import type {${[...referencedObjectDefs].join(",")}} from "../objects${importExt}";` : "";
|
|
834
1055
|
await fs.writeFile(path15__namespace.default.join(outDir, `${action.apiName}.ts`), await formatTs(`
|
|
835
|
-
import { ActionDefinition } from "@osdk/api";
|
|
836
|
-
|
|
837
|
-
|
|
1056
|
+
import type { ActionDefinition, ObjectActionDataType, ObjectSetActionDataType } from "@osdk/api";
|
|
1057
|
+
import type { ActionSignature, ApplyActionOptions, OsdkActionParameters,ActionReturnTypeForOptions, NOOP } from '@osdk/client';
|
|
1058
|
+
${importObjects}
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
${v2 ? createV2Types() : ""}
|
|
1062
|
+
|
|
1063
|
+
${v2 ? createV2Object() : createV1Object()}
|
|
1064
|
+
`));
|
|
838
1065
|
}));
|
|
839
1066
|
await fs.writeFile(path15__namespace.default.join(outDir, `index.ts`), await formatTs(`
|
|
840
|
-
${Object.values(ontology.actionTypes).map((action) => `export
|
|
1067
|
+
${Object.values(ontology.actionTypes).map((action) => `export {${action.apiName}} from "./${action.apiName}${importExt}";`).join("\n")}
|
|
841
1068
|
`));
|
|
842
1069
|
}
|
|
843
1070
|
function extractReferencedObjectsFromAction(actionType) {
|
|
@@ -905,6 +1132,7 @@ function wirePropertyV2ToSdkPrimaryKeyTypeDefinition(input) {
|
|
|
905
1132
|
}
|
|
906
1133
|
case "timeseries":
|
|
907
1134
|
case "array":
|
|
1135
|
+
case "marking":
|
|
908
1136
|
throw new Error(`Type not supported for primaryKey: ${input.dataType.type}`);
|
|
909
1137
|
default:
|
|
910
1138
|
input.dataType;
|
|
@@ -930,6 +1158,7 @@ function wirePropertyV2ToSdkPropertyDefinition(input, isNullable = true) {
|
|
|
930
1158
|
case "geoshape":
|
|
931
1159
|
case "timestamp":
|
|
932
1160
|
case "timeseries":
|
|
1161
|
+
case "marking":
|
|
933
1162
|
return {
|
|
934
1163
|
multiplicity: false,
|
|
935
1164
|
description: input.description,
|
|
@@ -964,6 +1193,7 @@ function objectPropertyTypeToSdkPropertyDefinition(propertyType) {
|
|
|
964
1193
|
case "geopoint":
|
|
965
1194
|
case "geoshape":
|
|
966
1195
|
case "timestamp":
|
|
1196
|
+
case "marking":
|
|
967
1197
|
return propertyType.type;
|
|
968
1198
|
case "date":
|
|
969
1199
|
return "datetime";
|
|
@@ -985,6 +1215,7 @@ function wireObjectTypeV2ToSdkObjectDefinition(objectTypeWithLink, v2) {
|
|
|
985
1215
|
throw new Error(`Primary key ${objectTypeWithLink.objectType.primaryKey} not found in ${objectTypeWithLink.objectType.apiName}`);
|
|
986
1216
|
}
|
|
987
1217
|
return {
|
|
1218
|
+
type: "object",
|
|
988
1219
|
apiName: objectTypeWithLink.objectType.apiName,
|
|
989
1220
|
description: objectTypeWithLink.objectType.description,
|
|
990
1221
|
primaryKeyType: wirePropertyV2ToSdkPrimaryKeyTypeDefinition(objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey]),
|
|
@@ -999,89 +1230,30 @@ function wireObjectTypeV2ToSdkObjectDefinition(objectTypeWithLink, v2) {
|
|
|
999
1230
|
}
|
|
1000
1231
|
|
|
1001
1232
|
// src/shared/wireObjectTypeV2ToSdkObjectConst.ts
|
|
1002
|
-
function wireObjectTypeV2ToSdkObjectConst(object, v2 = false) {
|
|
1233
|
+
function wireObjectTypeV2ToSdkObjectConst(object, importExt, v2 = false) {
|
|
1003
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}";`);
|
|
1004
1237
|
return `
|
|
1005
|
-
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
// src/v1.1/wireObjectTypeV2ToV1ObjectInterfaceString.ts
|
|
1015
|
-
function wireObjectTypeV2ToObjectInterfaceStringV1(objectTypeWithLinks, importExt = "") {
|
|
1016
|
-
const uniqueLinkTargets = new Set(objectTypeWithLinks.linkTypes.map((a) => a.objectTypeApiName).filter((a) => a !== objectTypeWithLinks.objectType.apiName));
|
|
1017
|
-
return `import type { OntologyObject, LocalDate, Timestamp, GeoShape, GeoPoint, Attachment, TimeSeries, MultiLink, SingleLink } from "@osdk/legacy-client";
|
|
1018
|
-
${Array.from(uniqueLinkTargets).map((linkTarget) => `import type { ${linkTarget} } from "./${linkTarget}${importExt}";`).join("\n")}
|
|
1019
|
-
|
|
1020
|
-
${getDescriptionIfPresent(objectTypeWithLinks.objectType.description)}export interface ${objectTypeWithLinks.objectType.apiName} extends OntologyObject {
|
|
1021
|
-
readonly __apiName: "${objectTypeWithLinks.objectType.apiName}";
|
|
1022
|
-
readonly __primaryKey: ${wirePropertyTypeV2ToTypeScriptType(objectTypeWithLinks.objectType.properties[objectTypeWithLinks.objectType.primaryKey].dataType)};
|
|
1023
|
-
${Object.entries(objectTypeWithLinks.objectType.properties).sort((a, b) => a[0].localeCompare(b[0])).flatMap(([propertyName, propertyDefinition]) => {
|
|
1024
|
-
const propertyType = wirePropertyTypeV2ToTypeScriptType(propertyDefinition.dataType);
|
|
1025
|
-
const entries = [`${getDescriptionIfPresent(propertyDefinition.description)}readonly ${propertyName}: ${propertyType} | undefined`];
|
|
1026
|
-
if (isReservedKeyword(propertyName)) {
|
|
1027
|
-
entries.push(`/** @deprecated please migrate to '${propertyName}' instead */
|
|
1028
|
-
readonly ${propertyName}_: ${propertyType} | undefined`);
|
|
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)},
|
|
1029
1247
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
${
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
}
|
|
1039
|
-
function wirePropertyTypeV2ToTypeScriptType(property) {
|
|
1040
|
-
switch (property.type) {
|
|
1041
|
-
case "string":
|
|
1042
|
-
return "string";
|
|
1043
|
-
case "boolean":
|
|
1044
|
-
return "boolean";
|
|
1045
|
-
case "array":
|
|
1046
|
-
return wirePropertyTypeV2ToTypeScriptType(property.subType) + "[]";
|
|
1047
|
-
case "integer":
|
|
1048
|
-
return "number";
|
|
1049
|
-
case "attachment":
|
|
1050
|
-
return "Attachment";
|
|
1051
|
-
case "byte":
|
|
1052
|
-
return "number";
|
|
1053
|
-
case "date":
|
|
1054
|
-
return "LocalDate";
|
|
1055
|
-
case "decimal":
|
|
1056
|
-
return "number";
|
|
1057
|
-
case "double":
|
|
1058
|
-
return "number";
|
|
1059
|
-
case "float":
|
|
1060
|
-
return "number";
|
|
1061
|
-
case "geopoint":
|
|
1062
|
-
return "GeoPoint";
|
|
1063
|
-
case "geoshape":
|
|
1064
|
-
return "GeoShape";
|
|
1065
|
-
case "long":
|
|
1066
|
-
return "number";
|
|
1067
|
-
case "short":
|
|
1068
|
-
return "number";
|
|
1069
|
-
case "timestamp":
|
|
1070
|
-
return "Timestamp";
|
|
1071
|
-
case "timeseries":
|
|
1072
|
-
return property.itemType.type === "string" ? `TimeSeries<string>` : `TimeSeries<number>`;
|
|
1073
|
-
default:
|
|
1074
|
-
throw new Error(`Unknown property type ${property}`);
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
function getDescriptionIfPresent(description) {
|
|
1078
|
-
if (description) {
|
|
1079
|
-
return `/**
|
|
1080
|
-
* ${description}
|
|
1081
|
-
*/
|
|
1082
|
-
`;
|
|
1083
|
-
}
|
|
1084
|
-
return "";
|
|
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
|
+
};`;
|
|
1085
1257
|
}
|
|
1086
1258
|
|
|
1087
1259
|
// src/v1.1/generatePerObjectInterfaceAndDataFiles.ts
|
|
@@ -1092,10 +1264,10 @@ async function generatePerObjectInterfaceAndDataFiles(ontology, fs, outDir, impo
|
|
|
1092
1264
|
await Promise.all(Object.values(ontology.objectTypes).map(async (object) => {
|
|
1093
1265
|
object.linkTypes;
|
|
1094
1266
|
await fs.writeFile(path15__namespace.default.join(outDir, `${object.objectType.apiName}.ts`), await formatTs(`
|
|
1095
|
-
import type { ObjectTypeDefinition } from "@osdk/api";
|
|
1267
|
+
import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from "@osdk/api";
|
|
1096
1268
|
${wireObjectTypeV2ToObjectInterfaceStringV1(object, importExt)}
|
|
1097
1269
|
|
|
1098
|
-
${wireObjectTypeV2ToSdkObjectConst(object)}
|
|
1270
|
+
${wireObjectTypeV2ToSdkObjectConst(object, importExt)}
|
|
1099
1271
|
`));
|
|
1100
1272
|
}));
|
|
1101
1273
|
await fs.writeFile(path15__namespace.default.join(outDir, "index.ts"), await formatTs(`
|
|
@@ -1158,7 +1330,7 @@ function wireQueryDataTypeToQueryDataTypeDefinition(input) {
|
|
|
1158
1330
|
case "union":
|
|
1159
1331
|
const allowNulls = isNullableQueryDataType(input);
|
|
1160
1332
|
if (allowNulls && input.unionTypes.length === 2) {
|
|
1161
|
-
const nonnull = input.unionTypes.find((t) => t.type
|
|
1333
|
+
const nonnull = input.unionTypes.find((t) => t.type != null);
|
|
1162
1334
|
if (nonnull) {
|
|
1163
1335
|
return {
|
|
1164
1336
|
...wireQueryDataTypeToQueryDataTypeDefinition(nonnull),
|
|
@@ -1241,6 +1413,7 @@ function guardInvalidKeyTypes(key) {
|
|
|
1241
1413
|
// src/shared/wireQueryTypeV2ToSdkQueryDefinition.ts
|
|
1242
1414
|
function wireQueryTypeV2ToSdkQueryDefinition(input) {
|
|
1243
1415
|
return {
|
|
1416
|
+
type: "query",
|
|
1244
1417
|
apiName: input.apiName,
|
|
1245
1418
|
description: input.description,
|
|
1246
1419
|
displayName: input.displayName,
|
|
@@ -1471,6 +1644,9 @@ async function generateClientSdkVersionOneDotOne(ontology, userAgent, fs, outDir
|
|
|
1471
1644
|
const actionsDir = path15__namespace.join(outDir, "ontology", "actions");
|
|
1472
1645
|
const queriesDir = path15__namespace.join(outDir, "ontology", "queries");
|
|
1473
1646
|
await verifyOutdir(outDir, fs);
|
|
1647
|
+
await fs.mkdir(outDir, {
|
|
1648
|
+
recursive: true
|
|
1649
|
+
});
|
|
1474
1650
|
const sanitizedOntology = sanitizeMetadata(ontology);
|
|
1475
1651
|
await generateFoundryClientFile(fs, outDir, importExt);
|
|
1476
1652
|
await generateMetadataFile(sanitizedOntology, userAgent, fs, outDir, importExt);
|
|
@@ -1479,7 +1655,8 @@ async function generateClientSdkVersionOneDotOne(ontology, userAgent, fs, outDir
|
|
|
1479
1655
|
await generateObjectsInterfaceSupportFiles(sanitizedOntology, fs, path15__namespace.join(objectsDir, "objects-api"), importExt);
|
|
1480
1656
|
await generatePerObjectInterfaceAndDataFiles(sanitizedOntology, fs, objectsDir, importExt);
|
|
1481
1657
|
await generateActions(sanitizedOntology, fs, actionsDir, importExt);
|
|
1482
|
-
await
|
|
1658
|
+
await generateBulkActions(sanitizedOntology, fs, actionsDir, importExt);
|
|
1659
|
+
await generatePerActionDataFiles(sanitizedOntology, fs, actionsDir, importExt, false);
|
|
1483
1660
|
await generateQueries(sanitizedOntology, fs, queriesDir, importExt);
|
|
1484
1661
|
await generatePerQueryDataFiles(sanitizedOntology, fs, queriesDir, importExt);
|
|
1485
1662
|
await generateIndexFile(fs, outDir, importExt);
|
|
@@ -1493,11 +1670,13 @@ function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceType, v2 = fals
|
|
|
1493
1670
|
}
|
|
1494
1671
|
function wireInterfaceTypeV2ToSdkObjectDefinition(interfaceType, v2) {
|
|
1495
1672
|
return {
|
|
1673
|
+
type: "interface",
|
|
1496
1674
|
apiName: interfaceType.apiName,
|
|
1497
1675
|
description: interfaceType.description,
|
|
1498
1676
|
properties: Object.fromEntries(Object.entries(interfaceType.properties).map(([key, value]) => {
|
|
1499
1677
|
return [key, wirePropertyV2ToSdkPropertyDefinition(value, true)];
|
|
1500
|
-
}))
|
|
1678
|
+
})),
|
|
1679
|
+
links: {}
|
|
1501
1680
|
};
|
|
1502
1681
|
}
|
|
1503
1682
|
async function generateOntologyMetadataFile(ontology, userAgent, fs, outDir) {
|
|
@@ -1567,9 +1746,9 @@ async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs, out
|
|
|
1567
1746
|
const obj = ontology.objectTypes[name];
|
|
1568
1747
|
await fs.writeFile(path15__namespace.default.join(outDir, "ontology", `objects`, `${name}.ts`), await formatTs(`
|
|
1569
1748
|
|
|
1570
|
-
import type { ObjectTypeDefinition } from "@osdk/api";
|
|
1749
|
+
import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from "@osdk/api";
|
|
1571
1750
|
|
|
1572
|
-
${wireObjectTypeV2ToSdkObjectConst(obj, true)}
|
|
1751
|
+
${wireObjectTypeV2ToSdkObjectConst(obj, importExt, true)}
|
|
1573
1752
|
|
|
1574
1753
|
${/* TODO: FIXME
|
|
1575
1754
|
// wireObjectTypeV2ToObjectDefinitionInterfaceString(
|
|
@@ -1584,7 +1763,7 @@ async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs, out
|
|
|
1584
1763
|
await fs.mkdir(actionsDir, {
|
|
1585
1764
|
recursive: true
|
|
1586
1765
|
});
|
|
1587
|
-
await generatePerActionDataFiles(sanitizedOntology, fs, actionsDir, importExt);
|
|
1766
|
+
await generatePerActionDataFiles(sanitizedOntology, fs, actionsDir, importExt, true);
|
|
1588
1767
|
await fs.writeFile(path15__namespace.default.join(outDir, "ontology", "objects.ts"), await formatTs(`
|
|
1589
1768
|
${Object.keys(ontology.objectTypes).map((apiName) => `export * from "./objects/${apiName}${importExt}";`).join("\n")}
|
|
1590
1769
|
`));
|