@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.mjs
CHANGED
|
@@ -139,6 +139,8 @@ function getTypeScriptTypeFromDataType(actionParameter, importedObjects) {
|
|
|
139
139
|
return `number`;
|
|
140
140
|
case "timestamp":
|
|
141
141
|
return `Timestamp`;
|
|
142
|
+
case "marking":
|
|
143
|
+
return "string";
|
|
142
144
|
default:
|
|
143
145
|
throw new Error(`Unsupported action parameter type: ${actionParameter}`);
|
|
144
146
|
}
|
|
@@ -533,6 +535,54 @@ async function generateBackCompatDeprecatedExports(fs, outDir, importExt = "") {
|
|
|
533
535
|
await generateOntologyRuntimeDistDir(outDir, fs, importExt);
|
|
534
536
|
await generateOAuthClientDistDir(outDir, fs, importExt);
|
|
535
537
|
}
|
|
538
|
+
async function generateBulkActions(ontology, fs, outDir, importExt = "") {
|
|
539
|
+
const importedObjects = /* @__PURE__ */ new Set();
|
|
540
|
+
let actionSignatures = [];
|
|
541
|
+
for (const action of Object.values(ontology.actionTypes)) {
|
|
542
|
+
const entries = Object.entries(action.parameters);
|
|
543
|
+
const modifiedEntityTypes = getModifiedEntityTypes(action);
|
|
544
|
+
const addedObjects = Array.from(modifiedEntityTypes.addedObjects);
|
|
545
|
+
const modifiedObjects = Array.from(modifiedEntityTypes.modifiedObjects);
|
|
546
|
+
addedObjects.forEach(importedObjects.add, importedObjects);
|
|
547
|
+
modifiedObjects.forEach(importedObjects.add, importedObjects);
|
|
548
|
+
let jsDocBlock = ["/**"];
|
|
549
|
+
if (action.description) {
|
|
550
|
+
jsDocBlock.push(`* ${action.description}`);
|
|
551
|
+
}
|
|
552
|
+
let parameterBlock = "";
|
|
553
|
+
if (entries.length > 0) {
|
|
554
|
+
parameterBlock = `params: {
|
|
555
|
+
`;
|
|
556
|
+
for (const [parameterName, parameterData] of entries) {
|
|
557
|
+
parameterBlock += `"${parameterName}"`;
|
|
558
|
+
parameterBlock += parameterData.required ? ": " : "?: ";
|
|
559
|
+
const typeScriptType = getTypeScriptTypeFromDataType(parameterData.dataType, importedObjects);
|
|
560
|
+
parameterBlock += `${typeScriptType};
|
|
561
|
+
`;
|
|
562
|
+
jsDocBlock.push(`* @param {${typeScriptType}} params.${parameterName}`);
|
|
563
|
+
}
|
|
564
|
+
parameterBlock += "}[], ";
|
|
565
|
+
} else {
|
|
566
|
+
parameterBlock = `params: Record<string,never>[], `;
|
|
567
|
+
}
|
|
568
|
+
jsDocBlock.push(`*/`);
|
|
569
|
+
actionSignatures.push(`
|
|
570
|
+
${jsDocBlock.join("\n")}
|
|
571
|
+
${action.apiName}<O extends BulkActionExecutionOptions>(${parameterBlock}options?: O):
|
|
572
|
+
Promise<Result<BulkActionResponseFromOptions<O, Edits<${addedObjects.length > 0 ? addedObjects.join(" | ") : "void"}, ${modifiedObjects.length > 0 ? modifiedObjects.join(" | ") : "void"}>>, ActionError>>;
|
|
573
|
+
`);
|
|
574
|
+
}
|
|
575
|
+
await fs.mkdir(outDir, {
|
|
576
|
+
recursive: true
|
|
577
|
+
});
|
|
578
|
+
await fs.writeFile(path15__default.join(outDir, "BulkActions.ts"), await formatTs(`
|
|
579
|
+
import type { ObjectSet, LocalDate, Timestamp, Attachment, Edits, ActionExecutionOptions, BulkActionExecutionOptions, ActionError, Result, ActionResponseFromOptions, BulkActionResponseFromOptions } from "@osdk/legacy-client";
|
|
580
|
+
${Array.from(importedObjects).map((importedObject) => `import type { ${importedObject} } from "../objects/${importedObject}${importExt}";`).join("\n")}
|
|
581
|
+
export interface BulkActions {
|
|
582
|
+
${actionSignatures.join("\n")}
|
|
583
|
+
}
|
|
584
|
+
`));
|
|
585
|
+
}
|
|
536
586
|
async function generateFoundryClientFile(fs, outDir, importExt = "") {
|
|
537
587
|
await fs.writeFile(path15__default.join(outDir, "FoundryClient.ts"), await formatTs(`
|
|
538
588
|
import { BaseFoundryClient } from "@osdk/legacy-client";
|
|
@@ -610,6 +660,7 @@ async function generateMetadataFile(ontology, userAgent, fs, outDir, importExt =
|
|
|
610
660
|
import type { Objects } from "./ontology/objects/Objects${importExt}";
|
|
611
661
|
import type { Actions } from "./ontology/actions/Actions${importExt}";
|
|
612
662
|
import type { Queries } from "./ontology/queries/Queries${importExt}";
|
|
663
|
+
import type { BulkActions } from "./ontology/actions/BulkActions${importExt}";
|
|
613
664
|
${objectNames.map((name) => `import {${name}} from "./ontology/objects/${name}${importExt}";`).join("\n")}
|
|
614
665
|
${actionNames.map((name) => `import {${getImportClause(name, actionAltNames)}} from "./ontology/actions/${name}${importExt}";`).join("\n")}
|
|
615
666
|
${queryNames.map((name) => `import {${getImportClause(name, queryAltNames)}} from "./ontology/queries/${name}${importExt}";`).join("\n")}
|
|
@@ -652,6 +703,7 @@ async function generateMetadataFile(ontology, userAgent, fs, outDir, importExt =
|
|
|
652
703
|
export interface Ontology extends ClientOntology<typeof Ontology> {
|
|
653
704
|
objects: Objects;
|
|
654
705
|
actions: Actions;
|
|
706
|
+
bulkActions: BulkActions;
|
|
655
707
|
queries: Queries;
|
|
656
708
|
}`));
|
|
657
709
|
}
|
|
@@ -719,6 +771,7 @@ async function generateOntologyIndexFile(fs, outDir) {
|
|
|
719
771
|
function wireActionTypeV2ToSdkActionDefinition(input) {
|
|
720
772
|
const modifiedEntityTypes = getModifiedEntityTypes(input);
|
|
721
773
|
return {
|
|
774
|
+
type: "action",
|
|
722
775
|
apiName: input.apiName,
|
|
723
776
|
parameters: Object.fromEntries(Object.entries(input.parameters).map(([key, value]) => [key, wireActionParameterV2ToSdkParameterDefinition(value)])),
|
|
724
777
|
displayName: input.displayName,
|
|
@@ -738,6 +791,7 @@ function wireActionParameterV2ToSdkParameterDefinition(value) {
|
|
|
738
791
|
case "long":
|
|
739
792
|
case "objectSet":
|
|
740
793
|
case "timestamp":
|
|
794
|
+
case "marking":
|
|
741
795
|
return {
|
|
742
796
|
multiplicity: false,
|
|
743
797
|
type: actionPropertyToSdkPropertyDefinition(value.dataType),
|
|
@@ -747,7 +801,7 @@ function wireActionParameterV2ToSdkParameterDefinition(value) {
|
|
|
747
801
|
case "array":
|
|
748
802
|
return {
|
|
749
803
|
multiplicity: true,
|
|
750
|
-
type: actionPropertyToSdkPropertyDefinition(value.dataType),
|
|
804
|
+
type: actionPropertyToSdkPropertyDefinition(value.dataType.subType),
|
|
751
805
|
nullable: value.required ? false : true,
|
|
752
806
|
description: value.description
|
|
753
807
|
};
|
|
@@ -762,6 +816,7 @@ function actionPropertyToSdkPropertyDefinition(parameterType) {
|
|
|
762
816
|
case "integer":
|
|
763
817
|
case "long":
|
|
764
818
|
case "timestamp":
|
|
819
|
+
case "marking":
|
|
765
820
|
return parameterType.type;
|
|
766
821
|
case "date":
|
|
767
822
|
return "datetime";
|
|
@@ -800,20 +855,192 @@ function createModifiedEntities(addedObjects, modifiedObjects) {
|
|
|
800
855
|
return entities;
|
|
801
856
|
}
|
|
802
857
|
|
|
858
|
+
// src/util/deleteUndefineds.ts
|
|
859
|
+
function deleteUndefineds(obj) {
|
|
860
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== void 0));
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// src/util/reservedKeywords.ts
|
|
864
|
+
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"]);
|
|
865
|
+
function isReservedKeyword(name) {
|
|
866
|
+
return reservedKeywords.has(name);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// src/v1.1/wireObjectTypeV2ToV1ObjectInterfaceString.ts
|
|
870
|
+
function wireObjectTypeV2ToObjectInterfaceStringV1(objectTypeWithLinks, importExt = "") {
|
|
871
|
+
const uniqueLinkTargets = new Set(objectTypeWithLinks.linkTypes.map((a) => a.objectTypeApiName).filter((a) => a !== objectTypeWithLinks.objectType.apiName));
|
|
872
|
+
return `import type { OntologyObject, LocalDate, Timestamp, GeoShape, GeoPoint, Attachment, TimeSeries, MultiLink, SingleLink } from "@osdk/legacy-client";
|
|
873
|
+
${Array.from(uniqueLinkTargets).map((linkTarget) => `import type { ${linkTarget} } from "./${linkTarget}${importExt}";`).join("\n")}
|
|
874
|
+
|
|
875
|
+
${getDescriptionIfPresent(objectTypeWithLinks.objectType.description)}
|
|
876
|
+
export interface ${objectTypeWithLinks.objectType.apiName} extends OntologyObject {
|
|
877
|
+
readonly __apiName: "${objectTypeWithLinks.objectType.apiName}";
|
|
878
|
+
readonly __primaryKey: ${wirePropertyTypeV2ToTypeScriptType(objectTypeWithLinks.objectType.properties[objectTypeWithLinks.objectType.primaryKey].dataType)};
|
|
879
|
+
${Object.entries(objectTypeWithLinks.objectType.properties).sort((a, b) => a[0].localeCompare(b[0])).flatMap(([propertyName, propertyDefinition]) => {
|
|
880
|
+
const propertyType = wirePropertyTypeV2ToTypeScriptType(propertyDefinition.dataType);
|
|
881
|
+
const entries = [`${getDescriptionIfPresent(propertyDefinition.description, true)}readonly ${propertyName}: ${propertyType} | undefined`];
|
|
882
|
+
if (isReservedKeyword(propertyName)) {
|
|
883
|
+
entries.push(`/** @deprecated please migrate to '${propertyName}' instead */
|
|
884
|
+
readonly ${propertyName}_: ${propertyType} | undefined`);
|
|
885
|
+
}
|
|
886
|
+
return entries;
|
|
887
|
+
}).join(";\n")}
|
|
888
|
+
${objectTypeWithLinks.linkTypes.flatMap((linkType) => {
|
|
889
|
+
const entries = [`readonly ${linkType.apiName}: ${linkType.cardinality === "MANY" ? "MultiLink" : "SingleLink"}<${linkType.objectTypeApiName}>`];
|
|
890
|
+
return entries;
|
|
891
|
+
}).join(";\n")}
|
|
892
|
+
}
|
|
893
|
+
`;
|
|
894
|
+
}
|
|
895
|
+
function wirePropertyTypeV2ToTypeScriptType(property) {
|
|
896
|
+
switch (property.type) {
|
|
897
|
+
case "string":
|
|
898
|
+
return "string";
|
|
899
|
+
case "boolean":
|
|
900
|
+
return "boolean";
|
|
901
|
+
case "array":
|
|
902
|
+
return wirePropertyTypeV2ToTypeScriptType(property.subType) + "[]";
|
|
903
|
+
case "integer":
|
|
904
|
+
return "number";
|
|
905
|
+
case "attachment":
|
|
906
|
+
return "Attachment";
|
|
907
|
+
case "byte":
|
|
908
|
+
return "number";
|
|
909
|
+
case "date":
|
|
910
|
+
return "LocalDate";
|
|
911
|
+
case "decimal":
|
|
912
|
+
return "number";
|
|
913
|
+
case "double":
|
|
914
|
+
return "number";
|
|
915
|
+
case "float":
|
|
916
|
+
return "number";
|
|
917
|
+
case "geopoint":
|
|
918
|
+
return "GeoPoint";
|
|
919
|
+
case "geoshape":
|
|
920
|
+
return "GeoShape";
|
|
921
|
+
case "long":
|
|
922
|
+
return "number";
|
|
923
|
+
case "short":
|
|
924
|
+
return "number";
|
|
925
|
+
case "timestamp":
|
|
926
|
+
return "Timestamp";
|
|
927
|
+
case "timeseries":
|
|
928
|
+
return property.itemType.type === "string" ? `TimeSeries<string>` : `TimeSeries<number>`;
|
|
929
|
+
case "marking":
|
|
930
|
+
return "string";
|
|
931
|
+
default:
|
|
932
|
+
throw new Error(`Unknown property type ${property}`);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
function getDescriptionIfPresent(description, includeNewline) {
|
|
936
|
+
if (description) {
|
|
937
|
+
return `/**
|
|
938
|
+
* ${description}
|
|
939
|
+
*/${includeNewline ? "\n" : ""}`;
|
|
940
|
+
}
|
|
941
|
+
return "";
|
|
942
|
+
}
|
|
943
|
+
|
|
803
944
|
// src/v1.1/generatePerActionDataFiles.ts
|
|
804
|
-
|
|
945
|
+
function stringifyWithoutOuterBraces(obj) {
|
|
946
|
+
return JSON.stringify(obj, null, 2).replace(/^\{\n/, "").replace(/\n\}$/, "");
|
|
947
|
+
}
|
|
948
|
+
async function generatePerActionDataFiles(ontology, fs, outDir, importExt, v2) {
|
|
805
949
|
await fs.mkdir(outDir, {
|
|
806
950
|
recursive: true
|
|
807
951
|
});
|
|
808
952
|
await Promise.all(Object.values(ontology.actionTypes).map(async (action) => {
|
|
809
953
|
const uniqueApiNames = new Set(extractReferencedObjectsFromAction(action));
|
|
954
|
+
const uniqueApiNamesString = uniqueApiNames.size > 0 ? [...uniqueApiNames].map((apiName) => `"${apiName}"`).join("|") : "never";
|
|
955
|
+
const fullActionDef = deleteUndefineds(wireActionTypeV2ToSdkActionDefinition(action));
|
|
956
|
+
const {
|
|
957
|
+
parameters,
|
|
958
|
+
...actionDefSansParameters
|
|
959
|
+
} = fullActionDef;
|
|
960
|
+
const actionDefIdentifier = `ActionDef$${action.apiName}`;
|
|
961
|
+
const paramsDefIdentifier = `${actionDefIdentifier}$Params`;
|
|
962
|
+
const paramsIdentifier = `${action.apiName}$Params`;
|
|
963
|
+
function createParamsDef() {
|
|
964
|
+
const entries = Object.entries(parameters);
|
|
965
|
+
if (entries.length === 0) {
|
|
966
|
+
return `// Represents the definition of the parameters for the action
|
|
967
|
+
export type ${paramsDefIdentifier} = Record<string, never>;`;
|
|
968
|
+
}
|
|
969
|
+
return `// Represents the definition of the parameters for the action
|
|
970
|
+
export type ${paramsDefIdentifier} = {
|
|
971
|
+
${Object.entries(parameters).map(([key, value]) => {
|
|
972
|
+
const {
|
|
973
|
+
type,
|
|
974
|
+
...remain
|
|
975
|
+
} = value;
|
|
976
|
+
let q;
|
|
977
|
+
if (typeof type === "string") {
|
|
978
|
+
q = JSON.stringify(type);
|
|
979
|
+
} else if (type.type === "object") {
|
|
980
|
+
q = `ObjectActionDataType<"${type.object}", ${type.object}Def>`;
|
|
981
|
+
} else if (type.type === "objectSet") {
|
|
982
|
+
q = `ObjectSetActionDataType<"${type.objectSet}", ${type.objectSet}Def>`;
|
|
983
|
+
}
|
|
984
|
+
return `"${key}": {
|
|
985
|
+
type: ${q};
|
|
986
|
+
${stringifyWithoutOuterBraces(remain)}
|
|
987
|
+
}
|
|
988
|
+
`;
|
|
989
|
+
}).join(";\n")}
|
|
990
|
+
}`;
|
|
991
|
+
}
|
|
992
|
+
function createV2Types() {
|
|
993
|
+
return `
|
|
994
|
+
|
|
995
|
+
${createParamsDef()}
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
// Represents the runtime arguments for the action
|
|
999
|
+
export type ${paramsIdentifier} = NOOP<OsdkActionParameters<${paramsDefIdentifier}>>;
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
// Represents a fqn of the action
|
|
1003
|
+
export interface ${action.apiName} {
|
|
1004
|
+
${getDescriptionIfPresent(action.description)}
|
|
1005
|
+
<OP extends ApplyActionOptions>(args: ${paramsIdentifier}, options?: OP): Promise<ActionReturnTypeForOptions<OP>>;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
// Represents the definition of the action
|
|
1010
|
+
export interface ${actionDefIdentifier} extends ActionDefinition<"${action.apiName}", ${uniqueApiNamesString}, ${action.apiName}>{
|
|
1011
|
+
${Object.entries(actionDefSansParameters).map(([key, value]) => {
|
|
1012
|
+
return `${key}: ${JSON.stringify(value)};`;
|
|
1013
|
+
}).join("\n")}
|
|
1014
|
+
parameters: ${paramsDefIdentifier}
|
|
1015
|
+
}`;
|
|
1016
|
+
}
|
|
1017
|
+
function createV2Object() {
|
|
1018
|
+
return ` export const ${action.apiName}: ${actionDefIdentifier} = ${JSON.stringify(fullActionDef, null, 2)} `;
|
|
1019
|
+
}
|
|
1020
|
+
function createV1Object() {
|
|
1021
|
+
return ` export const ${action.apiName} = ${JSON.stringify(fullActionDef, null, 2)} satisfies ActionDefinition<"${action.apiName}", ${uniqueApiNamesString}>;`;
|
|
1022
|
+
}
|
|
1023
|
+
const referencedObjectDefs = /* @__PURE__ */ new Set();
|
|
1024
|
+
for (const p of Object.values(action.parameters)) {
|
|
1025
|
+
if (p.dataType.type === "object" || p.dataType.type === "objectSet") {
|
|
1026
|
+
referencedObjectDefs.add(p.dataType.objectApiName + "Def");
|
|
1027
|
+
referencedObjectDefs.add(p.dataType.objectTypeApiName + "Def");
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
const importObjects = referencedObjectDefs.size > 0 ? `import type {${[...referencedObjectDefs].join(",")}} from "../objects${importExt}";` : "";
|
|
810
1031
|
await fs.writeFile(path15__default.join(outDir, `${action.apiName}.ts`), await formatTs(`
|
|
811
|
-
import { ActionDefinition } from "@osdk/api";
|
|
812
|
-
|
|
813
|
-
|
|
1032
|
+
import type { ActionDefinition, ObjectActionDataType, ObjectSetActionDataType } from "@osdk/api";
|
|
1033
|
+
import type { ActionSignature, ApplyActionOptions, OsdkActionParameters,ActionReturnTypeForOptions, NOOP } from '@osdk/client';
|
|
1034
|
+
${importObjects}
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
${v2 ? createV2Types() : ""}
|
|
1038
|
+
|
|
1039
|
+
${v2 ? createV2Object() : createV1Object()}
|
|
1040
|
+
`));
|
|
814
1041
|
}));
|
|
815
1042
|
await fs.writeFile(path15__default.join(outDir, `index.ts`), await formatTs(`
|
|
816
|
-
${Object.values(ontology.actionTypes).map((action) => `export
|
|
1043
|
+
${Object.values(ontology.actionTypes).map((action) => `export {${action.apiName}} from "./${action.apiName}${importExt}";`).join("\n")}
|
|
817
1044
|
`));
|
|
818
1045
|
}
|
|
819
1046
|
function extractReferencedObjectsFromAction(actionType) {
|
|
@@ -881,6 +1108,7 @@ function wirePropertyV2ToSdkPrimaryKeyTypeDefinition(input) {
|
|
|
881
1108
|
}
|
|
882
1109
|
case "timeseries":
|
|
883
1110
|
case "array":
|
|
1111
|
+
case "marking":
|
|
884
1112
|
throw new Error(`Type not supported for primaryKey: ${input.dataType.type}`);
|
|
885
1113
|
default:
|
|
886
1114
|
input.dataType;
|
|
@@ -906,6 +1134,7 @@ function wirePropertyV2ToSdkPropertyDefinition(input, isNullable = true) {
|
|
|
906
1134
|
case "geoshape":
|
|
907
1135
|
case "timestamp":
|
|
908
1136
|
case "timeseries":
|
|
1137
|
+
case "marking":
|
|
909
1138
|
return {
|
|
910
1139
|
multiplicity: false,
|
|
911
1140
|
description: input.description,
|
|
@@ -940,6 +1169,7 @@ function objectPropertyTypeToSdkPropertyDefinition(propertyType) {
|
|
|
940
1169
|
case "geopoint":
|
|
941
1170
|
case "geoshape":
|
|
942
1171
|
case "timestamp":
|
|
1172
|
+
case "marking":
|
|
943
1173
|
return propertyType.type;
|
|
944
1174
|
case "date":
|
|
945
1175
|
return "datetime";
|
|
@@ -961,6 +1191,7 @@ function wireObjectTypeV2ToSdkObjectDefinition(objectTypeWithLink, v2) {
|
|
|
961
1191
|
throw new Error(`Primary key ${objectTypeWithLink.objectType.primaryKey} not found in ${objectTypeWithLink.objectType.apiName}`);
|
|
962
1192
|
}
|
|
963
1193
|
return {
|
|
1194
|
+
type: "object",
|
|
964
1195
|
apiName: objectTypeWithLink.objectType.apiName,
|
|
965
1196
|
description: objectTypeWithLink.objectType.description,
|
|
966
1197
|
primaryKeyType: wirePropertyV2ToSdkPrimaryKeyTypeDefinition(objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey]),
|
|
@@ -975,89 +1206,30 @@ function wireObjectTypeV2ToSdkObjectDefinition(objectTypeWithLink, v2) {
|
|
|
975
1206
|
}
|
|
976
1207
|
|
|
977
1208
|
// src/shared/wireObjectTypeV2ToSdkObjectConst.ts
|
|
978
|
-
function wireObjectTypeV2ToSdkObjectConst(object, v2 = false) {
|
|
1209
|
+
function wireObjectTypeV2ToSdkObjectConst(object, importExt, v2 = false) {
|
|
979
1210
|
const uniqueLinkTargetTypes = new Set(object.linkTypes.map((a) => a.objectTypeApiName));
|
|
1211
|
+
const definition = wireObjectTypeV2ToSdkObjectDefinition(object, v2);
|
|
1212
|
+
const imports = Array.from(uniqueLinkTargetTypes).filter((type) => type !== definition.apiName).map((type) => `import type { ${type}Def } from "./${type}${importExt}";`);
|
|
980
1213
|
return `
|
|
981
|
-
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
// src/v1.1/wireObjectTypeV2ToV1ObjectInterfaceString.ts
|
|
991
|
-
function wireObjectTypeV2ToObjectInterfaceStringV1(objectTypeWithLinks, importExt = "") {
|
|
992
|
-
const uniqueLinkTargets = new Set(objectTypeWithLinks.linkTypes.map((a) => a.objectTypeApiName).filter((a) => a !== objectTypeWithLinks.objectType.apiName));
|
|
993
|
-
return `import type { OntologyObject, LocalDate, Timestamp, GeoShape, GeoPoint, Attachment, TimeSeries, MultiLink, SingleLink } from "@osdk/legacy-client";
|
|
994
|
-
${Array.from(uniqueLinkTargets).map((linkTarget) => `import type { ${linkTarget} } from "./${linkTarget}${importExt}";`).join("\n")}
|
|
995
|
-
|
|
996
|
-
${getDescriptionIfPresent(objectTypeWithLinks.objectType.description)}export interface ${objectTypeWithLinks.objectType.apiName} extends OntologyObject {
|
|
997
|
-
readonly __apiName: "${objectTypeWithLinks.objectType.apiName}";
|
|
998
|
-
readonly __primaryKey: ${wirePropertyTypeV2ToTypeScriptType(objectTypeWithLinks.objectType.properties[objectTypeWithLinks.objectType.primaryKey].dataType)};
|
|
999
|
-
${Object.entries(objectTypeWithLinks.objectType.properties).sort((a, b) => a[0].localeCompare(b[0])).flatMap(([propertyName, propertyDefinition]) => {
|
|
1000
|
-
const propertyType = wirePropertyTypeV2ToTypeScriptType(propertyDefinition.dataType);
|
|
1001
|
-
const entries = [`${getDescriptionIfPresent(propertyDefinition.description)}readonly ${propertyName}: ${propertyType} | undefined`];
|
|
1002
|
-
if (isReservedKeyword(propertyName)) {
|
|
1003
|
-
entries.push(`/** @deprecated please migrate to '${propertyName}' instead */
|
|
1004
|
-
readonly ${propertyName}_: ${propertyType} | undefined`);
|
|
1214
|
+
${imports.join("\n")}
|
|
1215
|
+
export interface ${object.objectType.apiName}Def extends ObjectTypeDefinition<"${object.objectType.apiName}"> {
|
|
1216
|
+
type: "${definition.type}",
|
|
1217
|
+
apiName: "${definition.apiName}",
|
|
1218
|
+
${definition.description != null ? `description: ${JSON.stringify(definition.description)},` : ""}
|
|
1219
|
+
primaryKeyType: ${JSON.stringify(definition.primaryKeyType)},
|
|
1220
|
+
links: {${Object.entries(definition.links).map(([linkApiName, definition2]) => `${linkApiName}: ObjectTypeLinkDefinition<${definition2.targetType}Def, ${definition2.multiplicity}>`).join(",\n")}
|
|
1221
|
+
},
|
|
1222
|
+
properties: ${JSON.stringify(definition.properties, null, 2)},
|
|
1005
1223
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
${
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
}
|
|
1015
|
-
function wirePropertyTypeV2ToTypeScriptType(property) {
|
|
1016
|
-
switch (property.type) {
|
|
1017
|
-
case "string":
|
|
1018
|
-
return "string";
|
|
1019
|
-
case "boolean":
|
|
1020
|
-
return "boolean";
|
|
1021
|
-
case "array":
|
|
1022
|
-
return wirePropertyTypeV2ToTypeScriptType(property.subType) + "[]";
|
|
1023
|
-
case "integer":
|
|
1024
|
-
return "number";
|
|
1025
|
-
case "attachment":
|
|
1026
|
-
return "Attachment";
|
|
1027
|
-
case "byte":
|
|
1028
|
-
return "number";
|
|
1029
|
-
case "date":
|
|
1030
|
-
return "LocalDate";
|
|
1031
|
-
case "decimal":
|
|
1032
|
-
return "number";
|
|
1033
|
-
case "double":
|
|
1034
|
-
return "number";
|
|
1035
|
-
case "float":
|
|
1036
|
-
return "number";
|
|
1037
|
-
case "geopoint":
|
|
1038
|
-
return "GeoPoint";
|
|
1039
|
-
case "geoshape":
|
|
1040
|
-
return "GeoShape";
|
|
1041
|
-
case "long":
|
|
1042
|
-
return "number";
|
|
1043
|
-
case "short":
|
|
1044
|
-
return "number";
|
|
1045
|
-
case "timestamp":
|
|
1046
|
-
return "Timestamp";
|
|
1047
|
-
case "timeseries":
|
|
1048
|
-
return property.itemType.type === "string" ? `TimeSeries<string>` : `TimeSeries<number>`;
|
|
1049
|
-
default:
|
|
1050
|
-
throw new Error(`Unknown property type ${property}`);
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
function getDescriptionIfPresent(description) {
|
|
1054
|
-
if (description) {
|
|
1055
|
-
return `/**
|
|
1056
|
-
* ${description}
|
|
1057
|
-
*/
|
|
1058
|
-
`;
|
|
1059
|
-
}
|
|
1060
|
-
return "";
|
|
1224
|
+
|
|
1225
|
+
export const ${object.objectType.apiName}: ${object.objectType.apiName}Def = {
|
|
1226
|
+
type: "${definition.type}",
|
|
1227
|
+
apiName: "${definition.apiName}",
|
|
1228
|
+
${definition.description != null ? `description: ${JSON.stringify(definition.description)},` : ""}
|
|
1229
|
+
primaryKeyType: ${JSON.stringify(definition.primaryKeyType)},
|
|
1230
|
+
links: ${JSON.stringify(definition.links, null, 2)},
|
|
1231
|
+
properties: ${JSON.stringify(definition.properties, null, 2)},
|
|
1232
|
+
};`;
|
|
1061
1233
|
}
|
|
1062
1234
|
|
|
1063
1235
|
// src/v1.1/generatePerObjectInterfaceAndDataFiles.ts
|
|
@@ -1068,10 +1240,10 @@ async function generatePerObjectInterfaceAndDataFiles(ontology, fs, outDir, impo
|
|
|
1068
1240
|
await Promise.all(Object.values(ontology.objectTypes).map(async (object) => {
|
|
1069
1241
|
object.linkTypes;
|
|
1070
1242
|
await fs.writeFile(path15__default.join(outDir, `${object.objectType.apiName}.ts`), await formatTs(`
|
|
1071
|
-
import type { ObjectTypeDefinition } from "@osdk/api";
|
|
1243
|
+
import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from "@osdk/api";
|
|
1072
1244
|
${wireObjectTypeV2ToObjectInterfaceStringV1(object, importExt)}
|
|
1073
1245
|
|
|
1074
|
-
${wireObjectTypeV2ToSdkObjectConst(object)}
|
|
1246
|
+
${wireObjectTypeV2ToSdkObjectConst(object, importExt)}
|
|
1075
1247
|
`));
|
|
1076
1248
|
}));
|
|
1077
1249
|
await fs.writeFile(path15__default.join(outDir, "index.ts"), await formatTs(`
|
|
@@ -1134,7 +1306,7 @@ function wireQueryDataTypeToQueryDataTypeDefinition(input) {
|
|
|
1134
1306
|
case "union":
|
|
1135
1307
|
const allowNulls = isNullableQueryDataType(input);
|
|
1136
1308
|
if (allowNulls && input.unionTypes.length === 2) {
|
|
1137
|
-
const nonnull = input.unionTypes.find((t) => t.type
|
|
1309
|
+
const nonnull = input.unionTypes.find((t) => t.type != null);
|
|
1138
1310
|
if (nonnull) {
|
|
1139
1311
|
return {
|
|
1140
1312
|
...wireQueryDataTypeToQueryDataTypeDefinition(nonnull),
|
|
@@ -1217,6 +1389,7 @@ function guardInvalidKeyTypes(key) {
|
|
|
1217
1389
|
// src/shared/wireQueryTypeV2ToSdkQueryDefinition.ts
|
|
1218
1390
|
function wireQueryTypeV2ToSdkQueryDefinition(input) {
|
|
1219
1391
|
return {
|
|
1392
|
+
type: "query",
|
|
1220
1393
|
apiName: input.apiName,
|
|
1221
1394
|
description: input.description,
|
|
1222
1395
|
displayName: input.displayName,
|
|
@@ -1447,6 +1620,9 @@ async function generateClientSdkVersionOneDotOne(ontology, userAgent, fs, outDir
|
|
|
1447
1620
|
const actionsDir = path15.join(outDir, "ontology", "actions");
|
|
1448
1621
|
const queriesDir = path15.join(outDir, "ontology", "queries");
|
|
1449
1622
|
await verifyOutdir(outDir, fs);
|
|
1623
|
+
await fs.mkdir(outDir, {
|
|
1624
|
+
recursive: true
|
|
1625
|
+
});
|
|
1450
1626
|
const sanitizedOntology = sanitizeMetadata(ontology);
|
|
1451
1627
|
await generateFoundryClientFile(fs, outDir, importExt);
|
|
1452
1628
|
await generateMetadataFile(sanitizedOntology, userAgent, fs, outDir, importExt);
|
|
@@ -1455,7 +1631,8 @@ async function generateClientSdkVersionOneDotOne(ontology, userAgent, fs, outDir
|
|
|
1455
1631
|
await generateObjectsInterfaceSupportFiles(sanitizedOntology, fs, path15.join(objectsDir, "objects-api"), importExt);
|
|
1456
1632
|
await generatePerObjectInterfaceAndDataFiles(sanitizedOntology, fs, objectsDir, importExt);
|
|
1457
1633
|
await generateActions(sanitizedOntology, fs, actionsDir, importExt);
|
|
1458
|
-
await
|
|
1634
|
+
await generateBulkActions(sanitizedOntology, fs, actionsDir, importExt);
|
|
1635
|
+
await generatePerActionDataFiles(sanitizedOntology, fs, actionsDir, importExt, false);
|
|
1459
1636
|
await generateQueries(sanitizedOntology, fs, queriesDir, importExt);
|
|
1460
1637
|
await generatePerQueryDataFiles(sanitizedOntology, fs, queriesDir, importExt);
|
|
1461
1638
|
await generateIndexFile(fs, outDir, importExt);
|
|
@@ -1469,11 +1646,13 @@ function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceType, v2 = fals
|
|
|
1469
1646
|
}
|
|
1470
1647
|
function wireInterfaceTypeV2ToSdkObjectDefinition(interfaceType, v2) {
|
|
1471
1648
|
return {
|
|
1649
|
+
type: "interface",
|
|
1472
1650
|
apiName: interfaceType.apiName,
|
|
1473
1651
|
description: interfaceType.description,
|
|
1474
1652
|
properties: Object.fromEntries(Object.entries(interfaceType.properties).map(([key, value]) => {
|
|
1475
1653
|
return [key, wirePropertyV2ToSdkPropertyDefinition(value, true)];
|
|
1476
|
-
}))
|
|
1654
|
+
})),
|
|
1655
|
+
links: {}
|
|
1477
1656
|
};
|
|
1478
1657
|
}
|
|
1479
1658
|
async function generateOntologyMetadataFile(ontology, userAgent, fs, outDir) {
|
|
@@ -1543,9 +1722,9 @@ async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs, out
|
|
|
1543
1722
|
const obj = ontology.objectTypes[name];
|
|
1544
1723
|
await fs.writeFile(path15__default.join(outDir, "ontology", `objects`, `${name}.ts`), await formatTs(`
|
|
1545
1724
|
|
|
1546
|
-
import type { ObjectTypeDefinition } from "@osdk/api";
|
|
1725
|
+
import type { ObjectTypeDefinition, ObjectTypeLinkDefinition } from "@osdk/api";
|
|
1547
1726
|
|
|
1548
|
-
${wireObjectTypeV2ToSdkObjectConst(obj, true)}
|
|
1727
|
+
${wireObjectTypeV2ToSdkObjectConst(obj, importExt, true)}
|
|
1549
1728
|
|
|
1550
1729
|
${/* TODO: FIXME
|
|
1551
1730
|
// wireObjectTypeV2ToObjectDefinitionInterfaceString(
|
|
@@ -1560,7 +1739,7 @@ async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs, out
|
|
|
1560
1739
|
await fs.mkdir(actionsDir, {
|
|
1561
1740
|
recursive: true
|
|
1562
1741
|
});
|
|
1563
|
-
await generatePerActionDataFiles(sanitizedOntology, fs, actionsDir, importExt);
|
|
1742
|
+
await generatePerActionDataFiles(sanitizedOntology, fs, actionsDir, importExt, true);
|
|
1564
1743
|
await fs.writeFile(path15__default.join(outDir, "ontology", "objects.ts"), await formatTs(`
|
|
1565
1744
|
${Object.keys(ontology.objectTypes).map((apiName) => `export * from "./objects/${apiName}${importExt}";`).join("\n")}
|
|
1566
1745
|
`));
|