@osdk/maker 0.13.0-beta.8 → 0.13.0-beta.9
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 +10 -0
- package/build/browser/api/defineObject.js +2 -0
- package/build/browser/api/defineObject.js.map +1 -1
- package/build/browser/api/overall.test.js +1 -1
- package/build/browser/api/overall.test.js.map +1 -1
- package/build/browser/cli/main.js +1 -1
- package/build/cjs/index.cjs +3 -1
- package/build/cjs/index.cjs.map +1 -1
- package/build/esm/api/defineObject.js +2 -0
- package/build/esm/api/defineObject.js.map +1 -1
- package/build/esm/api/overall.test.js +1 -1
- package/build/esm/api/overall.test.js.map +1 -1
- package/build/esm/cli/main.js +1 -1
- package/build/types/api/defineObject.d.ts.map +1 -1
- package/package.json +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -23,12 +23,14 @@ const ISO_8601_DURATION = /^P(?!$)(?:(?:((?:\d+Y)|(?:\d+(?:\.|,)\d+Y$))?((?:\d+M
|
|
|
23
23
|
|
|
24
24
|
// ISO 8601 date and time format (YYYY-MM-DDThh:mm:ss.sssZ)
|
|
25
25
|
const ISO_8601_DATETIME = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
26
|
+
const API_NAME_PATTERN = /^([a-zA-Z][a-zA-Z0-9\\-]*)$/;
|
|
26
27
|
export function defineObject(objectDef) {
|
|
27
28
|
const apiName = namespace + objectDef.apiName;
|
|
28
29
|
const propertyApiNames = objectDef.properties ? Object.keys(objectDef.properties) : [];
|
|
29
30
|
if (ontologyDefinition[OntologyEntityTypeEnum.OBJECT_TYPE][apiName] !== undefined) {
|
|
30
31
|
throw new Error(`Object type with apiName ${objectDef.apiName} is already defined`);
|
|
31
32
|
}
|
|
33
|
+
!API_NAME_PATTERN.test(objectDef.apiName) ? process.env.NODE_ENV !== "production" ? invariant(false, `Invalid API name ${objectDef.apiName}. API names must match the regex ${API_NAME_PATTERN}.`) : invariant(false) : void 0;
|
|
32
34
|
!propertyApiNames.includes(objectDef.titlePropertyApiName) ? process.env.NODE_ENV !== "production" ? invariant(false, `Title property ${objectDef.titlePropertyApiName} is not defined on object ${objectDef.apiName}`) : invariant(false) : void 0;
|
|
33
35
|
!propertyApiNames.includes(objectDef.primaryKeyPropertyApiName) ? process.env.NODE_ENV !== "production" ? invariant(false, `Primary key property ${objectDef.primaryKeyPropertyApiName} does not exist on object ${objectDef.apiName}`) : invariant(false) : void 0;
|
|
34
36
|
!!objectDef.properties?.[objectDef.primaryKeyPropertyApiName]?.editOnly ? process.env.NODE_ENV !== "production" ? invariant(false, `Primary key property ${objectDef.primaryKeyPropertyApiName} on object ${objectDef.apiName} cannot be edit-only`) : invariant(false) : void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineObject.js","names":["invariant","addNamespaceIfNone","namespace","ontologyDefinition","updateOntology","OntologyEntityTypeEnum","ISO_8601_DURATION","ISO_8601_DATETIME","defineObject","objectDef","apiName","propertyApiNames","properties","Object","keys","OBJECT_TYPE","undefined","Error","includes","titlePropertyApiName","process","env","NODE_ENV","primaryKeyPropertyApiName","editOnly","retentionPeriod","datasource","test","status","activeProperties","entries","forEach","property","push","length","join","type","deadline","isExotic","implementsInterfaces","interfaceImpl","allInterfaceProperties","getAllInterfaceProperties","implements","nonExistentInterfaceProperties","propertyMapping","map","val","interfaceProperty","filter","interfaceProp","reason","interfaceToObjectProperties","fromEntries","mapping","mapsTo","validateProperty","sharedPropertyType","validateInterfaceImplProperty","validations","allFailedValidations","concat","formatValidationErrors","flattenedProperties","convertUserObjectPropertyType","finalObject","__type","error","spt","mappedObjectProp","object","objProp","JSON","stringify","convertToDisplayName","s","charAt","toUpperCase","slice","convertToPluralDisplayName","endsWith","interfaceType","propertiesV2","extendsInterfaces","ext","displayName"],"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 ObjectPropertyType,\n ObjectPropertyTypeUserDefinition,\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): ObjectTypeDefinition {\n const apiName = namespace + objectDef.apiName;\n const propertyApiNames = objectDef.properties\n ? Object.keys(objectDef.properties)\n : [];\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?.[objectDef.primaryKeyPropertyApiName]?.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: string[] = [];\n Object.entries(objectDef.properties ?? {}).forEach(\n ([apiName, property]) => {\n if (property.status === \"active\") {\n activeProperties.push(apiName);\n }\n },\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 !isExotic(objectDef.properties?.[objectDef.titlePropertyApiName]?.type),\n `Title property ${objectDef.titlePropertyApiName} must be a primitive type`,\n );\n invariant(\n !isExotic(\n objectDef.properties?.[objectDef.primaryKeyPropertyApiName]?.type,\n ),\n `Primary key property ${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 flattenedProperties: Array<ObjectPropertyType> = Object.entries(\n objectDef.properties ?? {},\n ).map(([apiName, property]) =>\n convertUserObjectPropertyType(property.apiName ?? apiName, property)\n );\n\n const finalObject: ObjectType = {\n ...objectDef,\n apiName: apiName,\n __type: OntologyEntityTypeEnum.OBJECT_TYPE,\n properties: flattenedProperties,\n };\n updateOntology(finalObject);\n objectDef.apiName = apiName;\n return objectDef;\n}\n\nexport function isExotic(\n type: PropertyTypeType | undefined,\n): type is PropertyTypeTypeExotic {\n if (type === undefined) {\n return false;\n }\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?.[mappedObjectProp];\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\nfunction convertUserObjectPropertyType(\n apiName: string,\n property: ObjectPropertyTypeUserDefinition,\n): ObjectPropertyType {\n // fill in missing fields to be used by actions\n property.apiName = apiName;\n property.displayName = property.displayName ?? convertToDisplayName(apiName);\n return {\n ...property,\n apiName: apiName,\n displayName: property.displayName ?? convertToDisplayName(apiName),\n type: property.type,\n };\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;AAY5B,SAASC,sBAAsB,QAAQ,YAAY;;AAEnD;AACA,MAAMC,iBAAiB,GACrB,+OAA+O;;AAEjP;AACA,MAAMC,iBAAiB,GACrB,sEAAsE;AAExE,OAAO,SAASC,YAAYA,CAC1BC,SAA+B,EACT;EACtB,MAAMC,OAAO,GAAGR,SAAS,GAAGO,SAAS,CAACC,OAAO;EAC7C,MAAMC,gBAAgB,GAAGF,SAAS,CAACG,UAAU,GACzCC,MAAM,CAACC,IAAI,CAACL,SAAS,CAACG,UAAU,CAAC,GACjC,EAAE;EACN,IACET,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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AAoB,CAAChE,OAAO,CAAC;EAC5E,OAAO;IACL,GAAGsB,QAAQ;IACXtB,OAAO,EAAEA,OAAO;IAChB2E,WAAW,EAAErD,QAAQ,CAACqD,WAAW,IAAIX,oBAAoB,CAAChE,OAAO,CAAC;IAClE0B,IAAI,EAAEJ,QAAQ,CAACI;EACjB,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"defineObject.js","names":["invariant","addNamespaceIfNone","namespace","ontologyDefinition","updateOntology","OntologyEntityTypeEnum","ISO_8601_DURATION","ISO_8601_DATETIME","API_NAME_PATTERN","defineObject","objectDef","apiName","propertyApiNames","properties","Object","keys","OBJECT_TYPE","undefined","Error","test","process","env","NODE_ENV","includes","titlePropertyApiName","primaryKeyPropertyApiName","editOnly","retentionPeriod","datasource","status","activeProperties","entries","forEach","property","push","length","join","type","deadline","isExotic","implementsInterfaces","interfaceImpl","allInterfaceProperties","getAllInterfaceProperties","implements","nonExistentInterfaceProperties","propertyMapping","map","val","interfaceProperty","filter","interfaceProp","reason","interfaceToObjectProperties","fromEntries","mapping","mapsTo","validateProperty","sharedPropertyType","validateInterfaceImplProperty","validations","allFailedValidations","concat","formatValidationErrors","flattenedProperties","convertUserObjectPropertyType","finalObject","__type","error","spt","mappedObjectProp","object","objProp","JSON","stringify","convertToDisplayName","s","charAt","toUpperCase","slice","convertToPluralDisplayName","endsWith","interfaceType","propertiesV2","extendsInterfaces","ext","displayName"],"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 ObjectPropertyType,\n ObjectPropertyTypeUserDefinition,\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\nconst API_NAME_PATTERN = /^([a-zA-Z][a-zA-Z0-9\\\\-]*)$/;\n\nexport function defineObject(\n objectDef: ObjectTypeDefinition,\n): ObjectTypeDefinition {\n const apiName = namespace + objectDef.apiName;\n const propertyApiNames = objectDef.properties\n ? Object.keys(objectDef.properties)\n : [];\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 API_NAME_PATTERN.test(objectDef.apiName),\n `Invalid API name ${objectDef.apiName}. API names must match the regex ${API_NAME_PATTERN}.`,\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?.[objectDef.primaryKeyPropertyApiName]?.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: string[] = [];\n Object.entries(objectDef.properties ?? {}).forEach(\n ([apiName, property]) => {\n if (property.status === \"active\") {\n activeProperties.push(apiName);\n }\n },\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 !isExotic(objectDef.properties?.[objectDef.titlePropertyApiName]?.type),\n `Title property ${objectDef.titlePropertyApiName} must be a primitive type`,\n );\n invariant(\n !isExotic(\n objectDef.properties?.[objectDef.primaryKeyPropertyApiName]?.type,\n ),\n `Primary key property ${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 flattenedProperties: Array<ObjectPropertyType> = Object.entries(\n objectDef.properties ?? {},\n ).map(([apiName, property]) =>\n convertUserObjectPropertyType(property.apiName ?? apiName, property)\n );\n\n const finalObject: ObjectType = {\n ...objectDef,\n apiName: apiName,\n __type: OntologyEntityTypeEnum.OBJECT_TYPE,\n properties: flattenedProperties,\n };\n updateOntology(finalObject);\n objectDef.apiName = apiName;\n return objectDef;\n}\n\nexport function isExotic(\n type: PropertyTypeType | undefined,\n): type is PropertyTypeTypeExotic {\n if (type === undefined) {\n return false;\n }\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?.[mappedObjectProp];\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\nfunction convertUserObjectPropertyType(\n apiName: string,\n property: ObjectPropertyTypeUserDefinition,\n): ObjectPropertyType {\n // fill in missing fields to be used by actions\n property.apiName = apiName;\n property.displayName = property.displayName ?? convertToDisplayName(apiName);\n return {\n ...property,\n apiName: apiName,\n displayName: property.displayName ?? convertToDisplayName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A,QAAQ,CAACtB,OAAO,GAAGA,OAAO;EAC1BsB,QAAQ,CAACqD,WAAW,GAAGrD,QAAQ,CAACqD,WAAW,IAAIX,oBAAoB,CAAChE,OAAO,CAAC;EAC5E,OAAO;IACL,GAAGsB,QAAQ;IACXtB,OAAO,EAAEA,OAAO;IAChB2E,WAAW,EAAErD,QAAQ,CAACqD,WAAW,IAAIX,oBAAoB,CAAChE,OAAO,CAAC;IAClE0B,IAAI,EAAEJ,QAAQ,CAACI;EACjB,CAAC;AACH","ignoreList":[]}
|
|
@@ -1175,7 +1175,7 @@ defineOntology("com.palantir.",()=>{},"/tmp/");});describe("Interfaces",()=>{it(
|
|
|
1175
1175
|
},
|
|
1176
1176
|
},
|
|
1177
1177
|
}
|
|
1178
|
-
`);});it("defaults interface status to active",()=>{const result=defineInterface({apiName:"Foo"});expect(result.status).toEqual({type:"active",active:{}});});it("sets interface status as experimental from opts",()=>{const result=defineInterface({apiName:"Foo",status:{type:"experimental"}});expect(result.status).toEqual({type:"experimental",experimental:{}});});it("sets interface status as deprecated from opts",()=>{const result=defineInterface({apiName:"Foo",status:{type:"deprecated",message:"foo",deadline:"foo"}});expect(result.status).toEqual({type:"deprecated",deprecated:{message:"foo",deadline:"foo"}});});describe("Objects",()=>{it("Fails if any property reference does not exist",()=>{const spt=defineSharedPropertyType({apiName:"foo",type:"string"});const sample=defineInterface({apiName:"interface",properties:{foo:spt}});expect(()=>{defineObject({titlePropertyApiName:"fizz",displayName:"Foo",pluralDisplayName:"Foo",apiName:"foo",primaryKeyPropertyApiName:"bar",properties:{"bar":{type:"string"}}});}).toThrowErrorMatchingInlineSnapshot(`[Error: Invariant failed: Title property fizz is not defined on object foo]`);expect(()=>{defineObject({titlePropertyApiName:"bar",displayName:"Foo",pluralDisplayName:"Foo",apiName:"foo",primaryKeyPropertyApiName:"fizz",properties:{"bar":{type:"string"}}});}).toThrowErrorMatchingInlineSnapshot(`[Error: Invariant failed: Primary key property fizz does not exist on object foo]`);expect(()=>{defineObject({titlePropertyApiName:"bar",displayName:"Foo",pluralDisplayName:"Foo",apiName:"foo",primaryKeyPropertyApiName:"bar",properties:{"bar":{type:"string"}},implementsInterfaces:[{implements:sample,propertyMapping:[{interfaceProperty:"com.palantir.foo",mapsTo:"fizz"}]}]});}).toThrowErrorMatchingInlineSnapshot(`[Error: Invariant failed: \nOntology Definition Error: Object property mapped to interface does not exist. Object Property Mapped: fizz\n]`);expect(()=>{defineObject({titlePropertyApiName:"bar",displayName:"Foo",pluralDisplayName:"Foo",apiName:"foo",primaryKeyPropertyApiName:"bar",properties:{"bar":{type:"string"}},implementsInterfaces:[{implements:sample,propertyMapping:[{interfaceProperty:"com.palantir.fizz",mapsTo:"bar"},{interfaceProperty:"com.palantir.foo",mapsTo:"bar"}]}]});}).toThrowErrorMatchingInlineSnapshot(`[Error: Invariant failed: \nOntology Definition Error: Interface property com.palantir.fizz referenced in foo object does not exist\n]`);});it("Objects properly defined",()=>{const spt=defineSharedPropertyType({apiName:"foo",type:"string"});const sample=defineInterface({apiName:"interface",properties:{foo:spt}});defineObject({titlePropertyApiName:"bar",displayName:"Foo",pluralDisplayName:"Foo",apiName:"foo",primaryKeyPropertyApiName:"bar",properties:{"bar":{type:"string",displayName:"Bar"},"arrayProp":{type:"string",array:true,displayName:"Array Property Test"},"geopoint":{type:{type:"struct",structDefinition:{lat:"double",lng:"double"}},displayName:"geopoint"}},implementsInterfaces:[{implements:sample,propertyMapping:[{interfaceProperty:"foo",mapsTo:"bar"}]}]});expect(dumpOntologyFullMetadata().ontology).toMatchInlineSnapshot(`
|
|
1178
|
+
`);});it("defaults interface status to active",()=>{const result=defineInterface({apiName:"Foo"});expect(result.status).toEqual({type:"active",active:{}});});it("sets interface status as experimental from opts",()=>{const result=defineInterface({apiName:"Foo",status:{type:"experimental"}});expect(result.status).toEqual({type:"experimental",experimental:{}});});it("sets interface status as deprecated from opts",()=>{const result=defineInterface({apiName:"Foo",status:{type:"deprecated",message:"foo",deadline:"foo"}});expect(result.status).toEqual({type:"deprecated",deprecated:{message:"foo",deadline:"foo"}});});describe("Objects",()=>{it("Fails if the api name is invalid",()=>{expect(()=>{defineObject({titlePropertyApiName:"bar",displayName:"Foo",pluralDisplayName:"Foo",apiName:"foo_with_underscores",primaryKeyPropertyApiName:"bar",properties:{"bar":{type:"string"}}});}).toThrowErrorMatchingInlineSnapshot(`[Error: Invariant failed: Invalid API name foo_with_underscores. API names must match the regex /^([a-zA-Z][a-zA-Z0-9\\\\-]*)$/.]`);});it("Fails if any property reference does not exist",()=>{const spt=defineSharedPropertyType({apiName:"foo",type:"string"});const sample=defineInterface({apiName:"interface",properties:{foo:spt}});expect(()=>{defineObject({titlePropertyApiName:"fizz",displayName:"Foo",pluralDisplayName:"Foo",apiName:"foo",primaryKeyPropertyApiName:"bar",properties:{"bar":{type:"string"}}});}).toThrowErrorMatchingInlineSnapshot(`[Error: Invariant failed: Title property fizz is not defined on object foo]`);expect(()=>{defineObject({titlePropertyApiName:"bar",displayName:"Foo",pluralDisplayName:"Foo",apiName:"foo",primaryKeyPropertyApiName:"fizz",properties:{"bar":{type:"string"}}});}).toThrowErrorMatchingInlineSnapshot(`[Error: Invariant failed: Primary key property fizz does not exist on object foo]`);expect(()=>{defineObject({titlePropertyApiName:"bar",displayName:"Foo",pluralDisplayName:"Foo",apiName:"foo",primaryKeyPropertyApiName:"bar",properties:{"bar":{type:"string"}},implementsInterfaces:[{implements:sample,propertyMapping:[{interfaceProperty:"com.palantir.foo",mapsTo:"fizz"}]}]});}).toThrowErrorMatchingInlineSnapshot(`[Error: Invariant failed: \nOntology Definition Error: Object property mapped to interface does not exist. Object Property Mapped: fizz\n]`);expect(()=>{defineObject({titlePropertyApiName:"bar",displayName:"Foo",pluralDisplayName:"Foo",apiName:"foo",primaryKeyPropertyApiName:"bar",properties:{"bar":{type:"string"}},implementsInterfaces:[{implements:sample,propertyMapping:[{interfaceProperty:"com.palantir.fizz",mapsTo:"bar"},{interfaceProperty:"com.palantir.foo",mapsTo:"bar"}]}]});}).toThrowErrorMatchingInlineSnapshot(`[Error: Invariant failed: \nOntology Definition Error: Interface property com.palantir.fizz referenced in foo object does not exist\n]`);});it("Objects properly defined",()=>{const spt=defineSharedPropertyType({apiName:"foo",type:"string"});const sample=defineInterface({apiName:"interface",properties:{foo:spt}});defineObject({titlePropertyApiName:"bar",displayName:"Foo",pluralDisplayName:"Foo",apiName:"foo",primaryKeyPropertyApiName:"bar",properties:{"bar":{type:"string",displayName:"Bar"},"arrayProp":{type:"string",array:true,displayName:"Array Property Test"},"geopoint":{type:{type:"struct",structDefinition:{lat:"double",lng:"double"}},displayName:"geopoint"}},implementsInterfaces:[{implements:sample,propertyMapping:[{interfaceProperty:"foo",mapsTo:"bar"}]}]});expect(dumpOntologyFullMetadata().ontology).toMatchInlineSnapshot(`
|
|
1179
1179
|
{
|
|
1180
1180
|
"actionTypes": {},
|
|
1181
1181
|
"blockPermissionInformation": {
|