@osdk/maker 0.11.0-beta.9 → 0.11.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/CHANGELOG.md +168 -0
- package/build/browser/api/addDependency.js +20 -4
- package/build/browser/api/addDependency.js.map +1 -1
- package/build/browser/api/defineAction.js +7 -6
- package/build/browser/api/defineAction.js.map +1 -1
- package/build/browser/api/defineInterface.js +6 -5
- package/build/browser/api/defineInterface.js.map +1 -1
- package/build/browser/api/defineObject.js +20 -14
- package/build/browser/api/defineObject.js.map +1 -1
- package/build/browser/api/defineOntology.js +19 -13
- package/build/browser/api/defineOntology.js.map +1 -1
- package/build/browser/api/overall.test.js +1342 -718
- package/build/browser/api/overall.test.js.map +1 -1
- package/build/browser/api/types.js.map +1 -1
- package/build/browser/cli/main.js +1 -1
- package/build/browser/cli/main.js.map +1 -1
- package/build/cjs/index.cjs +81 -62
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +3 -2
- package/build/esm/api/addDependency.js +20 -4
- package/build/esm/api/addDependency.js.map +1 -1
- package/build/esm/api/defineAction.js +7 -6
- package/build/esm/api/defineAction.js.map +1 -1
- package/build/esm/api/defineInterface.js +6 -5
- package/build/esm/api/defineInterface.js.map +1 -1
- package/build/esm/api/defineObject.js +20 -14
- package/build/esm/api/defineObject.js.map +1 -1
- package/build/esm/api/defineOntology.js +19 -13
- package/build/esm/api/defineOntology.js.map +1 -1
- package/build/esm/api/overall.test.js +1342 -718
- package/build/esm/api/overall.test.js.map +1 -1
- package/build/esm/api/types.js.map +1 -1
- package/build/esm/cli/main.js +1 -1
- package/build/esm/cli/main.js.map +1 -1
- package/build/types/api/addDependency.d.ts +1 -1
- package/build/types/api/addDependency.d.ts.map +1 -1
- package/build/types/api/defineAction.d.ts.map +1 -1
- package/build/types/api/defineInterface.d.ts +1 -0
- package/build/types/api/defineInterface.d.ts.map +1 -1
- package/build/types/api/defineObject.d.ts +2 -1
- package/build/types/api/defineObject.d.ts.map +1 -1
- package/build/types/api/defineOntology.d.ts +1 -0
- package/build/types/api/defineOntology.d.ts.map +1 -1
- package/build/types/api/types.d.ts +1 -1
- package/build/types/api/types.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import invariant from "tiny-invariant";
|
|
18
|
-
import {
|
|
18
|
+
import { addNamespaceIfNone, namespace, ontologyDefinition, updateOntology } from "./defineOntology.js";
|
|
19
19
|
import { OntologyEntityTypeEnum } from "./types.js";
|
|
20
20
|
|
|
21
21
|
// From https://stackoverflow.com/a/79288714
|
|
@@ -49,28 +49,24 @@ export function defineObject(objectDef) {
|
|
|
49
49
|
!(objectDef.properties ?? []).filter(p => p.apiName === objectDef.titlePropertyApiName).every(p => !isExotic(p.type)) ? process.env.NODE_ENV !== "production" ? invariant(false, `Title property ${objectDef.titlePropertyApiName} must be a primitive type`) : invariant(false) : void 0;
|
|
50
50
|
!(objectDef.properties ?? []).filter(p => p.apiName === objectDef.primaryKeyPropertyApiName).every(p => !isExotic(p.type)) ? process.env.NODE_ENV !== "production" ? invariant(false, `Primary key properties ${objectDef.primaryKeyPropertyApiName} can only be primitive types`) : invariant(false) : void 0;
|
|
51
51
|
objectDef.implementsInterfaces?.forEach(interfaceImpl => {
|
|
52
|
-
const
|
|
52
|
+
const allInterfaceProperties = getAllInterfaceProperties(interfaceImpl.implements);
|
|
53
|
+
const nonExistentInterfaceProperties = interfaceImpl.propertyMapping.map(val => val.interfaceProperty).filter(interfaceProperty => allInterfaceProperties[addNamespaceIfNone(interfaceProperty)] === undefined).map(interfaceProp => ({
|
|
53
54
|
type: "invalid",
|
|
54
|
-
reason: `Interface property ${
|
|
55
|
+
reason: `Interface property ${interfaceProp} referenced in ${objectDef.apiName} object does not exist`
|
|
55
56
|
}));
|
|
56
|
-
const interfaceToObjectProperties = Object.fromEntries(interfaceImpl.propertyMapping.map(mapping => [mapping.interfaceProperty, mapping.mapsTo]));
|
|
57
|
+
const interfaceToObjectProperties = Object.fromEntries(interfaceImpl.propertyMapping.map(mapping => [addNamespaceIfNone(mapping.interfaceProperty), mapping.mapsTo]));
|
|
57
58
|
const validateProperty = interfaceProp => {
|
|
58
|
-
if (interfaceProp[1].sharedPropertyType.
|
|
59
|
+
if (interfaceProp[1].sharedPropertyType.apiName in interfaceToObjectProperties) {
|
|
59
60
|
return validateInterfaceImplProperty(interfaceProp[1].sharedPropertyType, interfaceToObjectProperties[interfaceProp[0]], objectDef);
|
|
60
61
|
}
|
|
61
62
|
return {
|
|
62
63
|
type: "invalid",
|
|
63
|
-
reason: `Interface property ${
|
|
64
|
+
reason: `Interface property ${interfaceProp[1].sharedPropertyType.apiName} not implemented by ${objectDef.apiName} object definition`
|
|
64
65
|
};
|
|
65
66
|
};
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const allFailedValidations = baseValidations.concat(extendsValidations, nonExistentInterfaceProperties).filter(val => val.type === "invalid");
|
|
67
|
+
const validations = Object.entries(getAllInterfaceProperties(interfaceImpl.implements)).map(validateProperty);
|
|
68
|
+
const allFailedValidations = validations.concat(nonExistentInterfaceProperties).filter(val => val.type === "invalid");
|
|
69
69
|
!(allFailedValidations.length === 0) ? process.env.NODE_ENV !== "production" ? invariant(false, "\n" + allFailedValidations.map(formatValidationErrors).join("\n")) : invariant(false) : void 0;
|
|
70
|
-
interfaceImpl.propertyMapping = interfaceImpl.propertyMapping.map(mapping => ({
|
|
71
|
-
interfaceProperty: extractNamespace(interfaceImpl.implements.apiName) + mapping.interfaceProperty,
|
|
72
|
-
mapsTo: mapping.mapsTo
|
|
73
|
-
}));
|
|
74
70
|
});
|
|
75
71
|
const finalObject = {
|
|
76
72
|
...objectDef,
|
|
@@ -101,7 +97,7 @@ function validateInterfaceImplProperty(spt, mappedObjectProp, object) {
|
|
|
101
97
|
reason: `Object property mapped to interface does not exist. Object Property Mapped: ${mappedObjectProp}`
|
|
102
98
|
};
|
|
103
99
|
}
|
|
104
|
-
if (spt.type !== objProp?.type) {
|
|
100
|
+
if (JSON.stringify(spt.type) !== JSON.stringify(objProp?.type)) {
|
|
105
101
|
return {
|
|
106
102
|
type: "invalid",
|
|
107
103
|
reason: `Object property type does not match the interface property it is mapped to. Interface Property: ${spt.apiName}, objectProperty: ${mappedObjectProp}`
|
|
@@ -119,4 +115,14 @@ export function convertToDisplayName(s) {
|
|
|
119
115
|
export function convertToPluralDisplayName(s) {
|
|
120
116
|
return s === undefined || s == null ? "" : s.endsWith("s") ? convertToDisplayName(s) : convertToDisplayName(s) + "s";
|
|
121
117
|
}
|
|
118
|
+
export function getAllInterfaceProperties(interfaceType) {
|
|
119
|
+
let properties = interfaceType.propertiesV2;
|
|
120
|
+
interfaceType.extendsInterfaces.forEach(ext => {
|
|
121
|
+
properties = {
|
|
122
|
+
...properties,
|
|
123
|
+
...getAllInterfaceProperties(ext)
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
return properties;
|
|
127
|
+
}
|
|
122
128
|
//# sourceMappingURL=defineObject.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineObject.js","names":["invariant","extractNamespace","namespace","ontologyDefinition","updateOntology","OntologyEntityTypeEnum","ISO_8601_DURATION","ISO_8601_DATETIME","defineObject","objectDef","apiName","propertyApiNames","properties","map","val","OBJECT_TYPE","undefined","Error","includes","titlePropertyApiName","process","env","NODE_ENV","primaryKeyPropertyApiName","filter","p","every","editOnly","retentionPeriod","datasource","test","status","activeProperties","property","length","join","type","deadline","isExotic","implementsInterfaces","forEach","interfaceImpl","nonExistentInterfaceProperties","propertyMapping","interfaceProperty","implements","propertiesV2","interfaceProp","reason","interfaceToObjectProperties","Object","fromEntries","mapping","mapsTo","validateProperty","sharedPropertyType","nonNameSpacedApiName","validateInterfaceImplProperty","baseValidations","entries","extendsValidations","extendsInterfaces","flatMap","interfaceType","allFailedValidations","concat","formatValidationErrors","finalObject","__type","error","spt","mappedObjectProp","object","objProp","find","prop","convertToDisplayName","s","charAt","toUpperCase","slice","convertToPluralDisplayName","endsWith"],"sources":["defineObject.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nimport {\n extractNamespace,\n namespace,\n ontologyDefinition,\n updateOntology,\n} from \"./defineOntology.js\";\nimport type {\n InterfacePropertyType,\n ObjectType,\n ObjectTypeDefinition,\n PropertyTypeType,\n PropertyTypeTypeExotic,\n SharedPropertyType,\n} from \"./types.js\";\nimport { OntologyEntityTypeEnum } from \"./types.js\";\n\n// From https://stackoverflow.com/a/79288714\nconst ISO_8601_DURATION =\n /^P(?!$)(?:(?:((?:\\d+Y)|(?:\\d+(?:\\.|,)\\d+Y$))?((?:\\d+M)|(?:\\d+(?:\\.|,)\\d+M$))?((?:\\d+D)|(?:\\d+(?:\\.|,)\\d+D$))?(T((?:\\d+H)|(?:\\d+(?:\\.|,)\\d+H$))?((?:\\d+M)|(?:\\d+(?:\\.|,)\\d+M$))?((?:\\d+S)|(?:\\d+(?:\\.|,)\\d+S$))?)?)|(?:\\d+(?:(?:\\.|,)\\d+)?W))$/;\n\n// ISO 8601 date and time format (YYYY-MM-DDThh:mm:ss.sssZ)\nconst ISO_8601_DATETIME =\n /^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})?)?$/;\n\nexport function defineObject(\n objectDef: ObjectTypeDefinition,\n): ObjectType {\n const apiName = namespace + objectDef.apiName;\n const propertyApiNames = (objectDef.properties ?? []).map(val => val.apiName);\n if (\n ontologyDefinition[OntologyEntityTypeEnum.OBJECT_TYPE][apiName]\n !== undefined\n ) {\n throw new Error(\n `Object type with apiName ${objectDef.apiName} is already defined`,\n );\n }\n invariant(\n propertyApiNames.includes(objectDef.titlePropertyApiName),\n `Title property ${objectDef.titlePropertyApiName} is not defined on object ${objectDef.apiName}`,\n );\n invariant(\n propertyApiNames.includes(objectDef.primaryKeyPropertyApiName),\n `Primary key property ${objectDef.primaryKeyPropertyApiName} does not exist on object ${objectDef.apiName}`,\n );\n\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.primaryKeyPropertyApiName\n ).every(p => !p.editOnly),\n `Primary key property ${objectDef.primaryKeyPropertyApiName} on object ${objectDef.apiName} cannot be edit-only`,\n );\n\n const retentionPeriod = (objectDef.datasource as any)?.retentionPeriod;\n invariant(\n retentionPeriod === undefined || ISO_8601_DURATION.test(retentionPeriod),\n `Retention period \"${retentionPeriod}\" on object \"${objectDef.apiName}\" is not a valid ISO 8601 duration string`,\n );\n\n // Validate that if object status is experimental, no property can have a status of active\n if (objectDef.status === \"experimental\") {\n const activeProperties = (objectDef.properties ?? [])\n .filter(property => property.status === \"active\")\n .map(property => property.apiName);\n\n invariant(\n activeProperties.length === 0,\n `When object \"${objectDef.apiName}\" has experimental status, no properties can have \"active\" status, but found active properties: ${\n activeProperties.join(\", \")\n }`,\n );\n }\n\n // Validate deprecated status deadline is in ISO 8601 format\n if (\n objectDef.status && typeof objectDef.status === \"object\"\n && objectDef.status.type === \"deprecated\"\n ) {\n const deadline = objectDef.status.deadline;\n invariant(\n deadline !== undefined && ISO_8601_DATETIME.test(deadline),\n `Deprecated status deadline \"${deadline}\" on object \"${objectDef.apiName}\" is not a valid ISO 8601 datetime string`,\n );\n }\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.titlePropertyApiName\n ).every(p => !isExotic(p.type)),\n `Title property ${objectDef.titlePropertyApiName} must be a primitive type`,\n );\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.primaryKeyPropertyApiName\n ).every(p => !isExotic(p.type)),\n `Primary key properties ${objectDef.primaryKeyPropertyApiName} can only be primitive types`,\n );\n\n objectDef.implementsInterfaces?.forEach(interfaceImpl => {\n const nonExistentInterfaceProperties: ValidationResult[] = interfaceImpl\n .propertyMapping.map(val => val.interfaceProperty).filter(\n interfaceProperty =>\n interfaceImpl.implements.propertiesV2[interfaceProperty]\n === undefined,\n ).map(interfaceProp => ({\n type: \"invalid\",\n reason:\n `Interface property ${interfaceImpl.implements.apiName}.${interfaceProp} referenced in ${objectDef.apiName} object does not exist`,\n }));\n\n const interfaceToObjectProperties = Object.fromEntries(\n interfaceImpl.propertyMapping.map(\n mapping => [mapping.interfaceProperty, mapping.mapsTo],\n ),\n );\n const validateProperty = (\n interfaceProp: [string, InterfacePropertyType],\n ): ValidationResult => {\n if (\n interfaceProp[1].sharedPropertyType.nonNameSpacedApiName\n in interfaceToObjectProperties\n ) {\n return validateInterfaceImplProperty(\n interfaceProp[1].sharedPropertyType,\n interfaceToObjectProperties[interfaceProp[0]],\n objectDef,\n );\n }\n return {\n type: \"invalid\",\n reason: `Interface property ${interfaceImpl.implements.apiName}.${\n interfaceProp[1].sharedPropertyType.nonNameSpacedApiName\n } not implemented by ${objectDef.apiName} object definition`,\n };\n };\n const baseValidations = Object.entries(\n interfaceImpl.implements.propertiesV2,\n )\n .map<ValidationResult>(validateProperty);\n const extendsValidations = interfaceImpl.implements.extendsInterfaces\n .flatMap(interfaceType =>\n Object.entries(interfaceType.propertiesV2).map(validateProperty)\n );\n\n const allFailedValidations = baseValidations.concat(\n extendsValidations,\n nonExistentInterfaceProperties,\n ).filter(val => val.type === \"invalid\");\n invariant(\n allFailedValidations.length === 0,\n \"\\n\" + allFailedValidations.map(formatValidationErrors).join(\"\\n\"),\n );\n\n interfaceImpl.propertyMapping = interfaceImpl.propertyMapping.map((\n mapping,\n ) => ({\n interfaceProperty: extractNamespace(interfaceImpl.implements.apiName)\n + mapping.interfaceProperty,\n mapsTo: mapping.mapsTo,\n }));\n });\n\n const finalObject: ObjectType = {\n ...objectDef,\n apiName: apiName,\n __type: OntologyEntityTypeEnum.OBJECT_TYPE,\n };\n updateOntology(finalObject);\n return finalObject;\n}\n\nexport function isExotic(\n type: PropertyTypeType,\n): type is PropertyTypeTypeExotic {\n if (typeof type === \"string\") {\n return [\"geopoint\", \"geoshape\", \"mediaReference\", \"geotimeSeries\"].includes(\n type,\n );\n } else if (typeof type === \"object\" && type != null) {\n return type.type === \"marking\" || type.type === \"struct\";\n }\n return false;\n}\n\ntype ValidationResult = { type: \"valid\" } | { type: \"invalid\"; reason: string };\n\nfunction formatValidationErrors(\n error: { type: \"invalid\"; reason: string },\n): string {\n return `Ontology Definition Error: ${error.reason}\\n`;\n}\n\n// Validate that the object and the interface property match up\nfunction validateInterfaceImplProperty(\n spt: SharedPropertyType,\n mappedObjectProp: string,\n object: ObjectTypeDefinition,\n): ValidationResult {\n const objProp = object.properties?.find(prop =>\n prop.apiName === mappedObjectProp\n );\n if (objProp === undefined) {\n return {\n type: \"invalid\",\n reason:\n `Object property mapped to interface does not exist. Object Property Mapped: ${mappedObjectProp}`,\n };\n }\n if (spt.type !== objProp?.type) {\n return {\n type: \"invalid\",\n reason:\n `Object property type does not match the interface property it is mapped to. Interface Property: ${spt.apiName}, objectProperty: ${mappedObjectProp}`,\n };\n }\n\n return { type: \"valid\" };\n}\n\nexport function convertToDisplayName(s: string | undefined | null): string {\n return s === undefined || s == null\n ? \"\"\n : s.charAt(0).toUpperCase() + s.slice(1);\n}\n\n// TODO: edge cases\nexport function convertToPluralDisplayName(\n s: string | undefined | null,\n): string {\n return s === undefined || s == null\n ? \"\"\n : s.endsWith(\"s\")\n ? convertToDisplayName(s)\n : convertToDisplayName(s) + \"s\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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KzD,SAAS,EAAE;IACzB,OAAO;MACLoB,IAAI,EAAE,SAAS;MACfY,MAAM,EACJ,+EAA+EuB,gBAAgB;IACnG,CAAC;EACH;EACA,IAAID,GAAG,CAAClC,IAAI,KAAKqC,OAAO,EAAErC,IAAI,EAAE;IAC9B,OAAO;MACLA,IAAI,EAAE,SAAS;MACfY,MAAM,EACJ,mGAAmGsB,GAAG,CAAC5D,OAAO,qBAAqB6D,gBAAgB;IACvJ,CAAC;EACH;EAEA,OAAO;IAAEnC,IAAI,EAAE;EAAQ,CAAC;AAC1B;AAEA,OAAO,SAASwC,oBAAoBA,CAACC,CAA4B,EAAU;EACzE,OAAOA,CAAC,KAAK7D,SAAS,IAAI6D,CAAC,IAAI,IAAI,GAC/B,EAAE,GACFA,CAAC,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGF,CAAC,CAACG,KAAK,CAAC,CAAC,CAAC;AAC5C;;AAEA;AACA,OAAO,SAASC,0BAA0BA,CACxCJ,CAA4B,EACpB;EACR,OAAOA,CAAC,KAAK7D,SAAS,IAAI6D,CAAC,IAAI,IAAI,GAC/B,EAAE,GACFA,CAAC,CAACK,QAAQ,CAAC,GAAG,CAAC,GACfN,oBAAoB,CAACC,CAAC,CAAC,GACvBD,oBAAoB,CAACC,CAAC,CAAC,GAAG,GAAG;AACnC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"defineObject.js","names":["invariant","addNamespaceIfNone","namespace","ontologyDefinition","updateOntology","OntologyEntityTypeEnum","ISO_8601_DURATION","ISO_8601_DATETIME","defineObject","objectDef","apiName","propertyApiNames","properties","map","val","OBJECT_TYPE","undefined","Error","includes","titlePropertyApiName","process","env","NODE_ENV","primaryKeyPropertyApiName","filter","p","every","editOnly","retentionPeriod","datasource","test","status","activeProperties","property","length","join","type","deadline","isExotic","implementsInterfaces","forEach","interfaceImpl","allInterfaceProperties","getAllInterfaceProperties","implements","nonExistentInterfaceProperties","propertyMapping","interfaceProperty","interfaceProp","reason","interfaceToObjectProperties","Object","fromEntries","mapping","mapsTo","validateProperty","sharedPropertyType","validateInterfaceImplProperty","validations","entries","allFailedValidations","concat","formatValidationErrors","finalObject","__type","error","spt","mappedObjectProp","object","objProp","find","prop","JSON","stringify","convertToDisplayName","s","charAt","toUpperCase","slice","convertToPluralDisplayName","endsWith","interfaceType","propertiesV2","extendsInterfaces","ext"],"sources":["defineObject.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nimport {\n addNamespaceIfNone,\n namespace,\n ontologyDefinition,\n updateOntology,\n} from \"./defineOntology.js\";\nimport type {\n InterfacePropertyType,\n InterfaceType,\n ObjectType,\n ObjectTypeDefinition,\n PropertyTypeType,\n PropertyTypeTypeExotic,\n SharedPropertyType,\n} from \"./types.js\";\nimport { OntologyEntityTypeEnum } from \"./types.js\";\n\n// From https://stackoverflow.com/a/79288714\nconst ISO_8601_DURATION =\n /^P(?!$)(?:(?:((?:\\d+Y)|(?:\\d+(?:\\.|,)\\d+Y$))?((?:\\d+M)|(?:\\d+(?:\\.|,)\\d+M$))?((?:\\d+D)|(?:\\d+(?:\\.|,)\\d+D$))?(T((?:\\d+H)|(?:\\d+(?:\\.|,)\\d+H$))?((?:\\d+M)|(?:\\d+(?:\\.|,)\\d+M$))?((?:\\d+S)|(?:\\d+(?:\\.|,)\\d+S$))?)?)|(?:\\d+(?:(?:\\.|,)\\d+)?W))$/;\n\n// ISO 8601 date and time format (YYYY-MM-DDThh:mm:ss.sssZ)\nconst ISO_8601_DATETIME =\n /^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})?)?$/;\n\nexport function defineObject(\n objectDef: ObjectTypeDefinition,\n): ObjectType {\n const apiName = namespace + objectDef.apiName;\n const propertyApiNames = (objectDef.properties ?? []).map(val => val.apiName);\n if (\n ontologyDefinition[OntologyEntityTypeEnum.OBJECT_TYPE][apiName]\n !== undefined\n ) {\n throw new Error(\n `Object type with apiName ${objectDef.apiName} is already defined`,\n );\n }\n invariant(\n propertyApiNames.includes(objectDef.titlePropertyApiName),\n `Title property ${objectDef.titlePropertyApiName} is not defined on object ${objectDef.apiName}`,\n );\n invariant(\n propertyApiNames.includes(objectDef.primaryKeyPropertyApiName),\n `Primary key property ${objectDef.primaryKeyPropertyApiName} does not exist on object ${objectDef.apiName}`,\n );\n\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.primaryKeyPropertyApiName\n ).every(p => !p.editOnly),\n `Primary key property ${objectDef.primaryKeyPropertyApiName} on object ${objectDef.apiName} cannot be edit-only`,\n );\n\n const retentionPeriod = (objectDef.datasource as any)?.retentionPeriod;\n invariant(\n retentionPeriod === undefined || ISO_8601_DURATION.test(retentionPeriod),\n `Retention period \"${retentionPeriod}\" on object \"${objectDef.apiName}\" is not a valid ISO 8601 duration string`,\n );\n\n // Validate that if object status is experimental, no property can have a status of active\n if (objectDef.status === \"experimental\") {\n const activeProperties = (objectDef.properties ?? [])\n .filter(property => property.status === \"active\")\n .map(property => property.apiName);\n\n invariant(\n activeProperties.length === 0,\n `When object \"${objectDef.apiName}\" has experimental status, no properties can have \"active\" status, but found active properties: ${\n activeProperties.join(\", \")\n }`,\n );\n }\n\n // Validate deprecated status deadline is in ISO 8601 format\n if (\n objectDef.status && typeof objectDef.status === \"object\"\n && objectDef.status.type === \"deprecated\"\n ) {\n const deadline = objectDef.status.deadline;\n invariant(\n deadline !== undefined && ISO_8601_DATETIME.test(deadline),\n `Deprecated status deadline \"${deadline}\" on object \"${objectDef.apiName}\" is not a valid ISO 8601 datetime string`,\n );\n }\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.titlePropertyApiName\n ).every(p => !isExotic(p.type)),\n `Title property ${objectDef.titlePropertyApiName} must be a primitive type`,\n );\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.primaryKeyPropertyApiName\n ).every(p => !isExotic(p.type)),\n `Primary key properties ${objectDef.primaryKeyPropertyApiName} can only be primitive types`,\n );\n\n objectDef.implementsInterfaces?.forEach(interfaceImpl => {\n const allInterfaceProperties = getAllInterfaceProperties(\n interfaceImpl.implements,\n );\n const nonExistentInterfaceProperties: ValidationResult[] = interfaceImpl\n .propertyMapping.map(val => val.interfaceProperty).filter(\n interfaceProperty =>\n allInterfaceProperties[addNamespaceIfNone(interfaceProperty)]\n === undefined,\n ).map(interfaceProp => ({\n type: \"invalid\",\n reason:\n `Interface property ${interfaceProp} referenced in ${objectDef.apiName} object does not exist`,\n }));\n\n const interfaceToObjectProperties = Object.fromEntries(\n interfaceImpl.propertyMapping.map(\n mapping => [\n addNamespaceIfNone(mapping.interfaceProperty),\n mapping.mapsTo,\n ],\n ),\n );\n const validateProperty = (\n interfaceProp: [string, InterfacePropertyType],\n ): ValidationResult => {\n if (\n interfaceProp[1].sharedPropertyType.apiName\n in interfaceToObjectProperties\n ) {\n return validateInterfaceImplProperty(\n interfaceProp[1].sharedPropertyType,\n interfaceToObjectProperties[interfaceProp[0]],\n objectDef,\n );\n }\n return {\n type: \"invalid\",\n reason: `Interface property ${\n interfaceProp[1].sharedPropertyType.apiName\n } not implemented by ${objectDef.apiName} object definition`,\n };\n };\n const validations = Object.entries(\n getAllInterfaceProperties(interfaceImpl.implements),\n ).map(validateProperty);\n const allFailedValidations = validations.concat(\n nonExistentInterfaceProperties,\n ).filter(val => val.type === \"invalid\");\n invariant(\n allFailedValidations.length === 0,\n \"\\n\" + allFailedValidations.map(formatValidationErrors).join(\"\\n\"),\n );\n });\n\n const finalObject: ObjectType = {\n ...objectDef,\n apiName: apiName,\n __type: OntologyEntityTypeEnum.OBJECT_TYPE,\n };\n updateOntology(finalObject);\n return finalObject;\n}\n\nexport function isExotic(\n type: PropertyTypeType,\n): type is PropertyTypeTypeExotic {\n if (typeof type === \"string\") {\n return [\"geopoint\", \"geoshape\", \"mediaReference\", \"geotimeSeries\"].includes(\n type,\n );\n } else if (typeof type === \"object\" && type != null) {\n return type.type === \"marking\" || type.type === \"struct\";\n }\n return false;\n}\n\ntype ValidationResult = { type: \"valid\" } | { type: \"invalid\"; reason: string };\n\nfunction formatValidationErrors(\n error: { type: \"invalid\"; reason: string },\n): string {\n return `Ontology Definition Error: ${error.reason}\\n`;\n}\n\n// Validate that the object and the interface property match up\nfunction validateInterfaceImplProperty(\n spt: SharedPropertyType,\n mappedObjectProp: string,\n object: ObjectTypeDefinition,\n): ValidationResult {\n const objProp = object.properties?.find(prop =>\n prop.apiName === mappedObjectProp\n );\n if (objProp === undefined) {\n return {\n type: \"invalid\",\n reason:\n `Object property mapped to interface does not exist. Object Property Mapped: ${mappedObjectProp}`,\n };\n }\n if (JSON.stringify(spt.type) !== JSON.stringify(objProp?.type)) {\n return {\n type: \"invalid\",\n reason:\n `Object property type does not match the interface property it is mapped to. Interface Property: ${spt.apiName}, objectProperty: ${mappedObjectProp}`,\n };\n }\n\n return { type: \"valid\" };\n}\n\nexport function convertToDisplayName(s: string | undefined | null): string {\n return s === undefined || s == null\n ? \"\"\n : s.charAt(0).toUpperCase() + s.slice(1);\n}\n\n// TODO: edge cases\nexport function convertToPluralDisplayName(\n s: string | undefined | null,\n): string {\n return s === undefined || s == null\n ? \"\"\n : s.endsWith(\"s\")\n ? convertToDisplayName(s)\n : convertToDisplayName(s) + \"s\";\n}\n\nexport function getAllInterfaceProperties(\n interfaceType: InterfaceType,\n): Record<string, InterfacePropertyType> {\n let properties = interfaceType.propertiesV2;\n interfaceType.extendsInterfaces.forEach(ext => {\n properties = { ...properties, ...getAllInterfaceProperties(ext) };\n });\n return properties;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SACEC,kBAAkB,EAClBC,SAAS,EACTC,kBAAkB,EAClBC,cAAc,QACT,qBAAqB;AAU5B,SAASC,sBAAsB,QAAQ,YAAY;;AAEnD;AACA,MAAMC,iBAAiB,GACrB,+OAA+O;;AAEjP;AACA,MAAMC,iBAAiB,GACrB,sEAAsE;AAExE,OAAO,SAASC,YAAYA,CAC1BC,SAA+B,EACnB;EACZ,MAAMC,OAAO,GAAGR,SAAS,GAAGO,SAAS,CAACC,OAAO;EAC7C,MAAMC,gBAAgB,GAAG,CAACF,SAAS,CAACG,UAAU,IAAI,EAAE,EAAEC,GAAG,CAACC,GAAG,IAAIA,GAAG,CAACJ,OAAO,CAAC;EAC7E,IACEP,kBAAkB,CAACE,sBAAsB,CAACU,WAAW,CAAC,CAACL,OAAO,CAAC,KACzDM,SAAS,EACf;IACA,MAAM,IAAIC,KAAK,CACb,4BAA4BR,SAAS,CAACC,OAAO,qBAC/C,CAAC;EACH;EACA,CACEC,gBAAgB,CAACO,QAAQ,CAACT,SAAS,CAACU,oBAAoB,CAAC,GAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD3DtB,SAAS,QAEP,kBAAkBS,SAAS,CAACU,oBAAoB,6BAA6BV,SAAS,CAACC,OAAO,EAAE,IAFlGV,SAAS;EAIT,CACEW,gBAAgB,CAACO,QAAQ,CAACT,SAAS,CAACc,yBAAyB,CAAC,GAAAH,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBADhEtB,SAAS,QAEP,wBAAwBS,SAAS,CAACc,yBAAyB,6BAA6Bd,SAAS,CAACC,OAAO,EAAE,IAF7GV,SAAS;EAKT,CACE,CAACS,SAAS,CAACG,UAAU,IAAI,EAA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J,mGAAmGiB,GAAG,CAACxD,OAAO,qBAAqByD,gBAAgB;IACvJ,CAAC;EACH;EAEA,OAAO;IAAE/B,IAAI,EAAE;EAAQ,CAAC;AAC1B;AAEA,OAAO,SAASsC,oBAAoBA,CAACC,CAA4B,EAAU;EACzE,OAAOA,CAAC,KAAK3D,SAAS,IAAI2D,CAAC,IAAI,IAAI,GAC/B,EAAE,GACFA,CAAC,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGF,CAAC,CAACG,KAAK,CAAC,CAAC,CAAC;AAC5C;;AAEA;AACA,OAAO,SAASC,0BAA0BA,CACxCJ,CAA4B,EACpB;EACR,OAAOA,CAAC,KAAK3D,SAAS,IAAI2D,CAAC,IAAI,IAAI,GAC/B,EAAE,GACFA,CAAC,CAACK,QAAQ,CAAC,GAAG,CAAC,GACfN,oBAAoB,CAACC,CAAC,CAAC,GACvBD,oBAAoB,CAACC,CAAC,CAAC,GAAG,GAAG;AACnC;AAEA,OAAO,SAAShC,yBAAyBA,CACvCsC,aAA4B,EACW;EACvC,IAAIrE,UAAU,GAAGqE,aAAa,CAACC,YAAY;EAC3CD,aAAa,CAACE,iBAAiB,CAAC3C,OAAO,CAAC4C,GAAG,IAAI;IAC7CxE,UAAU,GAAG;MAAE,GAAGA,UAAU;MAAE,GAAG+B,yBAAyB,CAACyC,GAAG;IAAE,CAAC;EACnE,CAAC,CAAC;EACF,OAAOxE,UAAU;AACnB","ignoreList":[]}
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
import * as fs from "fs";
|
|
18
18
|
import * as path from "path";
|
|
19
19
|
import invariant from "tiny-invariant";
|
|
20
|
-
import { fileURLToPath } from "url";
|
|
21
20
|
import { isExotic } from "./defineObject.js";
|
|
22
21
|
import { convertNullabilityToDataConstraint, convertType, convertValueType, convertValueTypeDataConstraints, defaultTypeClasses, getPropertyTypeName, hasRenderHints, shouldNotHaveRenderHints } from "./propertyConversionUtils.js";
|
|
23
22
|
import { OntologyEntityTypeEnum } from "./types.js";
|
|
@@ -194,7 +193,7 @@ function convertToWireImportedTypes(importedTypes) {
|
|
|
194
193
|
apiName: i.interfaceType.apiName,
|
|
195
194
|
displayName: i.interfaceType.displayMetadata.displayName,
|
|
196
195
|
description: i.interfaceType.displayMetadata.description,
|
|
197
|
-
properties: Object.values(i.interfaceType.
|
|
196
|
+
properties: Object.values(i.interfaceType.propertiesV2).map(p => ({
|
|
198
197
|
apiName: p.sharedPropertyType.apiName,
|
|
199
198
|
displayName: p.sharedPropertyType.displayMetadata.displayName,
|
|
200
199
|
description: p.sharedPropertyType.displayMetadata.description,
|
|
@@ -313,7 +312,7 @@ function convertObject(objectType) {
|
|
|
313
312
|
redacted: false,
|
|
314
313
|
implementsInterfaces2: implementations.map(impl => ({
|
|
315
314
|
interfaceTypeApiName: impl.implements.apiName,
|
|
316
|
-
properties: Object.fromEntries(impl.propertyMapping.map(mapping => [mapping.interfaceProperty, {
|
|
315
|
+
properties: Object.fromEntries(impl.propertyMapping.map(mapping => [addNamespaceIfNone(mapping.interfaceProperty), {
|
|
317
316
|
propertyTypeRid: mapping.mapsTo
|
|
318
317
|
}]))
|
|
319
318
|
})),
|
|
@@ -446,7 +445,12 @@ function convertProperty(property) {
|
|
|
446
445
|
indexedForSearch: property.indexedForSearch ?? true,
|
|
447
446
|
ruleSetBinding: undefined,
|
|
448
447
|
baseFormatter: property.baseFormatter,
|
|
449
|
-
type:
|
|
448
|
+
type: property.array ? {
|
|
449
|
+
type: "array",
|
|
450
|
+
array: {
|
|
451
|
+
subtype: convertType(property.type)
|
|
452
|
+
}
|
|
453
|
+
} : convertType(property.type),
|
|
450
454
|
typeClasses: property.typeClasses ?? (shouldNotHaveRenderHints(property.type) ? [] : defaultTypeClasses),
|
|
451
455
|
status: convertObjectStatus(property.status),
|
|
452
456
|
inlineAction: undefined,
|
|
@@ -585,6 +589,9 @@ function convertInterface(interfaceType) {
|
|
|
585
589
|
allLinks: [],
|
|
586
590
|
allProperties: [],
|
|
587
591
|
allPropertiesV2: {},
|
|
592
|
+
// TODO(mwalther): Support propertiesV3
|
|
593
|
+
propertiesV3: {},
|
|
594
|
+
allPropertiesV3: {},
|
|
588
595
|
properties: []
|
|
589
596
|
};
|
|
590
597
|
}
|
|
@@ -731,6 +738,7 @@ function convertActionValidation(action) {
|
|
|
731
738
|
},
|
|
732
739
|
parameterValidations: Object.fromEntries((action.parameters ?? []).map(p => {
|
|
733
740
|
return [p.id, {
|
|
741
|
+
conditionalOverrides: [],
|
|
734
742
|
defaultValidation: {
|
|
735
743
|
display: {
|
|
736
744
|
renderHint: renderHintFromBaseType(p),
|
|
@@ -1039,14 +1047,12 @@ function writeDependencyFile(dependencyFile) {
|
|
|
1039
1047
|
}
|
|
1040
1048
|
function dependencyInjectionString() {
|
|
1041
1049
|
const namespaceNoDot = namespace.endsWith(".") ? namespace.slice(0, -1) : namespace;
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
const currentPackageVersion = packageJson.version ?? "";
|
|
1050
|
-
return `import { addDependency } from '@osdk/maker';\n\naddDependency("${namespaceNoDot}", "${currentPackageVersion}");\n`;
|
|
1050
|
+
return `import { addDependency } from "@osdk/maker";
|
|
1051
|
+
|
|
1052
|
+
addDependency("${namespaceNoDot}", new URL(import.meta.url).pathname);
|
|
1053
|
+
`;
|
|
1054
|
+
}
|
|
1055
|
+
export function addNamespaceIfNone(apiName) {
|
|
1056
|
+
return apiName.includes(".") ? apiName : namespace + apiName;
|
|
1051
1057
|
}
|
|
1052
1058
|
//# sourceMappingURL=defineOntology.js.map
|