@osdk/faux 0.4.0-beta.1 → 0.4.0-beta.3

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/build/browser/FauxFoundry/FauxAttachmentStore.js +4 -2
  3. package/build/browser/FauxFoundry/FauxAttachmentStore.js.map +1 -1
  4. package/build/browser/FauxFoundry/FauxDataStore.js +8 -4
  5. package/build/browser/FauxFoundry/FauxDataStore.js.map +1 -1
  6. package/build/browser/FauxFoundry/FauxDataStoreBatch.js +2 -1
  7. package/build/browser/FauxFoundry/FauxDataStoreBatch.js.map +1 -1
  8. package/build/browser/FauxFoundry/validateAction.js +85 -13
  9. package/build/browser/FauxFoundry/validateAction.js.map +1 -1
  10. package/build/browser/FauxFoundry/validateAction.test.js +522 -0
  11. package/build/browser/FauxFoundry/validateAction.test.js.map +1 -0
  12. package/build/browser/handlers/util/handleOpenApiCall.js.map +1 -1
  13. package/build/cjs/index.cjs +130 -50
  14. package/build/cjs/index.cjs.map +1 -1
  15. package/build/cjs/index.d.cts +5 -3
  16. package/build/esm/FauxFoundry/FauxAttachmentStore.js +4 -2
  17. package/build/esm/FauxFoundry/FauxAttachmentStore.js.map +1 -1
  18. package/build/esm/FauxFoundry/FauxDataStore.js +8 -4
  19. package/build/esm/FauxFoundry/FauxDataStore.js.map +1 -1
  20. package/build/esm/FauxFoundry/FauxDataStoreBatch.js +2 -1
  21. package/build/esm/FauxFoundry/FauxDataStoreBatch.js.map +1 -1
  22. package/build/esm/FauxFoundry/validateAction.js +85 -13
  23. package/build/esm/FauxFoundry/validateAction.js.map +1 -1
  24. package/build/esm/FauxFoundry/validateAction.test.js +522 -0
  25. package/build/esm/FauxFoundry/validateAction.test.js.map +1 -0
  26. package/build/esm/handlers/util/handleOpenApiCall.js.map +1 -1
  27. package/build/types/FauxFoundry/FauxAttachmentStore.d.ts.map +1 -1
  28. package/build/types/FauxFoundry/FauxDataStore.d.ts.map +1 -1
  29. package/build/types/FauxFoundry/FauxDataStoreBatch.d.ts.map +1 -1
  30. package/build/types/FauxFoundry/validateAction.d.ts +2 -1
  31. package/build/types/FauxFoundry/validateAction.d.ts.map +1 -1
  32. package/build/types/FauxFoundry/validateAction.test.d.ts +1 -0
  33. package/build/types/FauxFoundry/validateAction.test.d.ts.map +1 -0
  34. package/build/types/handlers/util/handleOpenApiCall.d.ts +6 -4
  35. package/build/types/handlers/util/handleOpenApiCall.d.ts.map +1 -1
  36. package/package.json +5 -4
@@ -1 +1 @@
1
- {"version":3,"file":"validateAction.js","names":["validateAction","payload","def","dataStore","ret","parameters","submissionCriteria","result","k","v","Object","entries","value","validateActionParameterType","dataType","paramDef","paramKey","required","evaluatedConstraints","baseParam","type","Array","isArray","item","subType","matchesOntologyDataType","isInterfaceActionParam","getObject","objectTypeApiName","primaryKeyValue","isMediaReference","name","fieldType","fields","fieldValue","ontology","getObjectTypeFullMetadata","Error","odt","every","itemType","Number","isInteger","o","mimeType","reference","mediaSetViewItem","mediaSetRid","mediaSetViewRid","mediaItemRid","isPoint","obj","coordinates","length"],"sources":["validateAction.ts"],"sourcesContent":["/*\n * Copyright 2025 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 type { MediaReference } from \"@osdk/foundry.core\";\nimport type {\n ActionParameterType,\n ActionParameterV2,\n ActionTypeV2,\n ApplyActionRequestV2,\n BatchApplyActionRequestItem,\n OntologyDataType,\n ParameterEvaluationResult,\n ValidateActionResponseV2,\n} from \"@osdk/foundry.ontologies\";\nimport type { FauxDataStore } from \"./FauxDataStore.js\";\n\nexport function validateAction(\n payload: ApplyActionRequestV2 | BatchApplyActionRequestItem,\n def: ActionTypeV2,\n dataStore: FauxDataStore,\n): ValidateActionResponseV2 {\n const ret: ValidateActionResponseV2 = {\n parameters: {},\n submissionCriteria: [],\n result: \"VALID\",\n };\n for (const [k, v] of Object.entries(def.parameters)) {\n const value = payload.parameters[k];\n validateActionParameterType(v.dataType, v, value, ret, k, dataStore);\n }\n\n return ret;\n}\n\n// So far these all basically return the same thing\n// and can likely be rewritten as a function that return boolean\nfunction validateActionParameterType(\n dataType: ActionParameterType,\n paramDef: ActionParameterV2,\n value: unknown,\n ret: ValidateActionResponseV2,\n paramKey: string,\n dataStore: FauxDataStore,\n) {\n if (paramDef.required && value == null) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n result: \"INVALID\",\n evaluatedConstraints: [],\n required: true,\n };\n return;\n }\n if (!paramDef.required && value == null) {\n return;\n }\n\n const baseParam: ParameterEvaluationResult = {\n result: \"INVALID\",\n evaluatedConstraints: [],\n required: paramDef.required,\n };\n\n switch (dataType.type) {\n case \"array\": {\n if (!Array.isArray(value)) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n return;\n }\n for (const item of value) {\n validateActionParameterType(\n dataType.subType,\n paramDef,\n item,\n ret,\n paramKey,\n dataStore,\n );\n }\n return;\n }\n\n case \"attachment\": {\n if (typeof value !== \"string\") {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n }\n return;\n }\n\n case \"boolean\":\n case \"date\":\n case \"long\":\n case \"double\":\n case \"integer\":\n case \"marking\":\n case \"objectSet\":\n case \"timestamp\":\n case \"object\":\n case \"string\":\n if (!matchesOntologyDataType(dataType, value)) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n }\n return;\n case \"geohash\":\n if (!(typeof value === \"string\")) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n }\n return;\n\n case \"geoshape\":\n if (\n !(typeof value === \"object\"\n && (\"coordinates\" in value! || \"geometries\" in value!\n || \"features\" in value!))\n ) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n }\n return;\n case \"interfaceObject\": {\n if (!isInterfaceActionParam(value)) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n } else if (\n dataStore.getObject(\n value.objectTypeApiName,\n value.primaryKeyValue,\n ) == null\n ) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n evaluatedConstraints: [{\n type: \"objectPropertyValue\",\n }],\n };\n }\n return;\n }\n\n case \"mediaReference\": {\n if (!isMediaReference(value)) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n }\n return;\n }\n\n case \"vector\": {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n return;\n }\n\n case \"struct\": {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n return;\n }\n\n for (const { name, fieldType, required } of dataType.fields) {\n const fieldValue = (value as Record<string, unknown>)[name];\n if (\n (required && fieldValue == null)\n || !matchesOntologyDataType(fieldType, fieldValue)\n ) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n\n return;\n }\n }\n\n return;\n }\n\n case \"objectType\": {\n if (\n typeof value !== \"string\"\n || !dataStore.ontology.getObjectTypeFullMetadata(value)\n ) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n return;\n }\n\n return;\n }\n\n default: {\n const _assertNever: never = dataType;\n throw new Error(\n `validateDataType: unknown type`,\n );\n }\n }\n}\n\nfunction matchesOntologyDataType(\n odt: OntologyDataType,\n value: unknown,\n): boolean {\n switch (odt.type) {\n case \"any\":\n return true;\n case \"array\":\n return Array.isArray(value)\n && value.every((v) => matchesOntologyDataType(odt.itemType, v));\n case \"binary\":\n throw new Error(`validateDataType: ${odt.type} not implemented yet.`);\n case \"boolean\":\n return typeof value === \"boolean\";\n case \"byte\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"cipherText\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"date\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"decimal\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"double\":\n return typeof value === \"number\";\n\n case \"float\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"integer\":\n return (typeof value === \"number\" && Number.isInteger(value));\n\n case \"long\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"map\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"marking\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"object\":\n return typeof value === \"string\"\n || (value != null && typeof value === \"object\"\n && \"$primaryKey\" in value);\n case \"objectSet\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"set\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"short\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"string\":\n return (typeof value === \"string\");\n\n case \"struct\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"timestamp\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"unsupported\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n default:\n const _assertNever = odt;\n throw new Error(\n `matchesOntologyDataType: ${(odt as any).type} not implemented yet.`,\n );\n }\n}\n\nexport function isMediaReference(o: any): o is MediaReference {\n return typeof o === `object`\n && typeof o.mimeType === \"string\"\n && \"reference\" in o\n && typeof o.reference === \"object\"\n && o.reference.type === \"mediaSetViewItem\"\n && \"mediaSetViewItem\" in o.reference\n && typeof o.reference.mediaSetViewItem === \"object\"\n && typeof o.reference.mediaSetViewItem.mediaSetRid === \"string\"\n && typeof o.reference.mediaSetViewItem.mediaSetViewRid === \"string\"\n && typeof o.reference.mediaSetViewItem.mediaItemRid === \"string\";\n}\n\nexport function isInterfaceActionParam(value: any): value is {\n objectTypeApiName: string;\n primaryKeyValue: string | number | boolean;\n} {\n return (\n typeof value === \"object\"\n && \"objectTypeApiName\" in value\n && typeof value.objectTypeApiName === \"string\"\n && \"primaryKeyValue\" in value\n && (typeof value.primaryKeyValue === \"string\"\n || typeof value.primaryKeyValue === \"number\"\n || typeof value.primaryKeyValue === \"boolean\")\n );\n}\n\nfunction isPoint(obj: any): obj is GeoJSON.Point {\n return obj.type === \"Point\"\n && Array.isArray(obj.coordinates)\n && obj.coordinates.length === 2\n && typeof obj.coordinates[0] === \"number\"\n && typeof obj.coordinates[1] === \"number\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA,OAAO,SAASA,cAAcA,CAC5BC,OAA2D,EAC3DC,GAAiB,EACjBC,SAAwB,EACE;EAC1B,MAAMC,GAA6B,GAAG;IACpCC,UAAU,EAAE,CAAC,CAAC;IACdC,kBAAkB,EAAE,EAAE;IACtBC,MAAM,EAAE;EACV,CAAC;EACD,KAAK,MAAM,CAACC,CAAC,EAAEC,CAAC,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACT,GAAG,CAACG,UAAU,CAAC,EAAE;IACnD,MAAMO,KAAK,GAAGX,OAAO,CAACI,UAAU,CAACG,CAAC,CAAC;IACnCK,2BAA2B,CAACJ,CAAC,CAACK,QAAQ,EAAEL,CAAC,EAAEG,KAAK,EAAER,GAAG,EAAEI,CAAC,EAAE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UE","float","integer","long","MIN_SAFE_INTEGER","MAX_SAFE_INTEGER","short","validateAction","payload","def","dataStore","ret","parameters","submissionCriteria","result","k","v","Object","entries","value","validateActionParameterType","dataType","paramDef","paramKey","required","evaluatedConstraints","baseParam","type","Array","isArray","item","subType","matchesOntologyDataType","isInterfaceActionParam","getObject","objectTypeApiName","primaryKeyValue","isMediaReference","name","fieldType","fields","fieldValue","ontology","getObjectTypeFullMetadata","Error","odt","every","itemType","isInBounds","isValidCipherText","isValidDateString","isValidDecimalString","isInteger","startsWith","isValidTimestampString","o","mimeType","reference","mediaSetViewItem","mediaSetRid","mediaSetViewRid","mediaItemRid","isPoint","obj","coordinates","length","bounds","test","date","Date","isNaN","getTime","toISOString","parts","split","isValidCipherAffix","channelRid","encryptedValue","affix","prefixOnly","totalParts","parseFloat"],"sources":["validateAction.ts"],"sourcesContent":["/*\n * Copyright 2025 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 type { MediaReference } from \"@osdk/foundry.core\";\nimport type {\n ActionParameterType,\n ActionParameterV2,\n ActionTypeV2,\n ApplyActionRequestV2,\n BatchApplyActionRequestItem,\n OntologyDataType,\n ParameterEvaluationResult,\n ValidateActionResponseV2,\n} from \"@osdk/foundry.ontologies\";\nimport type { FauxDataStore } from \"./FauxDataStore.js\";\n\ninterface Bounds {\n minimum: number;\n maximum: number;\n}\n\nconst NUMERIC_LITERAL_BOUNDS: Record<\n Extract<\n OntologyDataType[\"type\"],\n \"double\" | \"integer\" | \"long\" | \"float\" | \"byte\" | \"short\"\n >,\n Bounds\n> = {\n byte: {\n // Java min/max byte bounds\n minimum: -128,\n maximum: 127,\n },\n double: {\n // These numbers are smaller than the actual min/max of a java double,\n // but going higher will require using BigInt in our input fields.\n minimum: -Number.MAX_VALUE,\n maximum: Number.MAX_VALUE,\n },\n float: {\n // Java min/max float bounds\n minimum: -3.4028235e38,\n maximum: 3.4028235e38,\n },\n integer: {\n // Java min/max integer bounds\n minimum: -2147483648,\n maximum: 2147483647,\n },\n long: {\n // These numbers are smaller than the actual min/max of a java long,\n // but going higher will require using BigInt in our input fields.\n minimum: Number.MIN_SAFE_INTEGER,\n maximum: Number.MAX_SAFE_INTEGER,\n },\n short: {\n // Java min/max short bounds\n minimum: -32768,\n maximum: 32767,\n },\n} as const;\n\nexport function validateAction(\n payload: ApplyActionRequestV2 | BatchApplyActionRequestItem,\n def: ActionTypeV2,\n dataStore: FauxDataStore,\n): ValidateActionResponseV2 {\n const ret: ValidateActionResponseV2 = {\n parameters: {},\n submissionCriteria: [],\n result: \"VALID\",\n };\n for (const [k, v] of Object.entries(def.parameters)) {\n const value = payload.parameters[k];\n validateActionParameterType(v.dataType, v, value, ret, k, dataStore);\n }\n\n return ret;\n}\n\n// So far these all basically return the same thing\n// and can likely be rewritten as a function that return boolean\nfunction validateActionParameterType(\n dataType: ActionParameterType,\n paramDef: ActionParameterV2,\n value: unknown,\n ret: ValidateActionResponseV2,\n paramKey: string,\n dataStore: FauxDataStore,\n) {\n if (paramDef.required && value == null) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n result: \"INVALID\",\n evaluatedConstraints: [],\n required: true,\n };\n return;\n }\n if (!paramDef.required && value == null) {\n return;\n }\n\n const baseParam: ParameterEvaluationResult = {\n result: \"INVALID\",\n evaluatedConstraints: [],\n required: paramDef.required,\n };\n\n switch (dataType.type) {\n case \"array\": {\n if (!Array.isArray(value)) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n return;\n }\n for (const item of value) {\n validateActionParameterType(\n dataType.subType,\n paramDef,\n item,\n ret,\n paramKey,\n dataStore,\n );\n }\n return;\n }\n\n case \"attachment\": {\n if (typeof value !== \"string\") {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n }\n return;\n }\n\n case \"boolean\":\n case \"date\":\n case \"long\":\n case \"double\":\n case \"integer\":\n case \"marking\":\n case \"objectSet\":\n case \"timestamp\":\n case \"object\":\n case \"string\":\n if (!matchesOntologyDataType(dataType, value)) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n }\n return;\n case \"geohash\":\n if (!(typeof value === \"string\")) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n }\n return;\n\n case \"geoshape\":\n if (\n !(typeof value === \"object\"\n && (\"coordinates\" in value! || \"geometries\" in value!\n || \"features\" in value!))\n ) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n }\n return;\n case \"interfaceObject\": {\n if (!isInterfaceActionParam(value)) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n } else if (\n dataStore.getObject(\n value.objectTypeApiName,\n value.primaryKeyValue,\n ) == null\n ) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n evaluatedConstraints: [{\n type: \"objectPropertyValue\",\n }],\n };\n }\n return;\n }\n\n case \"mediaReference\": {\n if (!isMediaReference(value)) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n }\n return;\n }\n\n case \"vector\": {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n return;\n }\n\n case \"struct\": {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n return;\n }\n\n for (const { name, fieldType, required } of dataType.fields) {\n const fieldValue = (value as Record<string, unknown>)[name];\n if (\n (required && fieldValue == null)\n || !matchesOntologyDataType(fieldType, fieldValue)\n ) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n\n return;\n }\n }\n\n return;\n }\n\n case \"objectType\": {\n if (\n typeof value !== \"string\"\n || !dataStore.ontology.getObjectTypeFullMetadata(value)\n ) {\n ret.result = \"INVALID\";\n ret.parameters[paramKey] = {\n ...baseParam,\n };\n return;\n }\n\n return;\n }\n\n default: {\n const _assertNever: never = dataType;\n throw new Error(\n `validateDataType: unknown type`,\n );\n }\n }\n}\n\nexport function matchesOntologyDataType(\n odt: OntologyDataType,\n value: unknown,\n): boolean {\n switch (odt.type) {\n case \"any\":\n return true;\n case \"array\":\n return Array.isArray(value)\n && value.every((v) => matchesOntologyDataType(odt.itemType, v));\n case \"binary\":\n throw new Error(`validateDataType: ${odt.type} not implemented yet.`);\n case \"boolean\":\n return typeof value === \"boolean\";\n case \"byte\":\n return typeof value === \"number\"\n && isInBounds(value, NUMERIC_LITERAL_BOUNDS.byte);\n case \"cipherText\":\n return isValidCipherText(value);\n case \"date\":\n return isValidDateString(value);\n case \"decimal\":\n return isValidDecimalString(value);\n case \"double\":\n return typeof value === \"number\"\n && isInBounds(value, NUMERIC_LITERAL_BOUNDS.double);\n case \"float\":\n return typeof value === \"number\"\n && isInBounds(value, NUMERIC_LITERAL_BOUNDS.float);\n case \"integer\":\n return (typeof value === \"number\" && Number.isInteger(value)\n && isInBounds(value, NUMERIC_LITERAL_BOUNDS.integer));\n case \"long\":\n return (typeof value === \"number\" && Number.isInteger(value)\n && isInBounds(value, NUMERIC_LITERAL_BOUNDS.long));\n case \"map\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"marking\":\n return typeof value === \"string\";\n case \"object\":\n return typeof value === \"string\"\n || (value != null && typeof value === \"object\"\n && \"$primaryKey\" in value);\n case \"objectSet\":\n return typeof value === \"string\" && value.startsWith(\"ri.\")\n || (value != null && typeof value === \"object\"\n && \"objectSet\" in value);\n case \"set\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"short\":\n return typeof value === \"number\"\n && isInBounds(value, NUMERIC_LITERAL_BOUNDS.short);\n case \"string\":\n return (typeof value === \"string\");\n case \"struct\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n case \"timestamp\":\n return isValidTimestampString(value);\n case \"unsupported\":\n throw new Error(\n `matchesOntologyDataType: ${odt.type} not implemented yet.`,\n );\n default:\n const _assertNever = odt;\n throw new Error(\n `matchesOntologyDataType: ${(odt as any).type} not implemented yet.`,\n );\n }\n}\n\nexport function isMediaReference(o: any): o is MediaReference {\n return typeof o === `object`\n && typeof o.mimeType === \"string\"\n && \"reference\" in o\n && typeof o.reference === \"object\"\n && o.reference.type === \"mediaSetViewItem\"\n && \"mediaSetViewItem\" in o.reference\n && typeof o.reference.mediaSetViewItem === \"object\"\n && typeof o.reference.mediaSetViewItem.mediaSetRid === \"string\"\n && typeof o.reference.mediaSetViewItem.mediaSetViewRid === \"string\"\n && typeof o.reference.mediaSetViewItem.mediaItemRid === \"string\";\n}\n\nexport function isInterfaceActionParam(value: any): value is {\n objectTypeApiName: string;\n primaryKeyValue: string | number | boolean;\n} {\n return (\n typeof value === \"object\"\n && \"objectTypeApiName\" in value\n && typeof value.objectTypeApiName === \"string\"\n && \"primaryKeyValue\" in value\n && (typeof value.primaryKeyValue === \"string\"\n || typeof value.primaryKeyValue === \"number\"\n || typeof value.primaryKeyValue === \"boolean\")\n );\n}\n\nfunction isPoint(obj: any): obj is GeoJSON.Point {\n return obj.type === \"Point\"\n && Array.isArray(obj.coordinates)\n && obj.coordinates.length === 2\n && typeof obj.coordinates[0] === \"number\"\n && typeof obj.coordinates[1] === \"number\";\n}\n\nfunction isInBounds(\n value: number,\n bounds: { minimum: number; maximum: number },\n) {\n return bounds.minimum <= value && value <= bounds.maximum;\n}\n\nfunction isValidDateString(value: unknown): boolean {\n if (typeof value !== \"string\") {\n return false;\n }\n\n const dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n if (!dateRegex.test(value)) {\n return false;\n }\n const date = new Date(value);\n return !isNaN(date.getTime()) && date.toISOString().startsWith(value);\n}\n\nfunction isValidTimestampString(value: unknown): boolean {\n return typeof value === \"string\" && !isNaN(new Date(value).getTime());\n}\n\nfunction isValidCipherText(value: unknown): boolean {\n if (typeof value !== \"string\") {\n return false;\n }\n\n const parts = value.split(\"::\");\n\n if (\n !(isValidCipherAffix(parts, \"CIPHER\")\n || isValidCipherAffix(parts, \"BELLASO\")\n || isValidCipherAffix(parts, \"BELLASO\", true))\n ) {\n return false;\n }\n\n const channelRid = parts[1];\n const encryptedValue = parts[2];\n\n return channelRid.startsWith(\"ri.\") && encryptedValue !== \"\";\n}\n\nfunction isValidCipherAffix(\n parts: string[],\n affix: \"BELLASO\" | \"CIPHER\",\n prefixOnly: boolean = false,\n): boolean {\n const totalParts = prefixOnly ? 3 : 4;\n\n return parts.length === totalParts && parts[0] === affix\n && (prefixOnly || parts[3] === affix);\n}\n\nfunction isValidDecimalString(value: unknown): boolean {\n if (typeof value !== \"string\") {\n return false;\n }\n\n const decimalRegex = /^[+-]?(\\d+\\.?\\d*|\\.\\d+)(E[+-]?\\d+)?$/;\n return decimalRegex.test(value) && !isNaN(parseFloat(value));\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAoBA,MAAMA,sBAML,GAAG;EACFC,IAAI,EAAE;IACJ;IACAC,OAAO,EAAE,CAAC,GAAG;IACbC,OAAO,EAAE;EACX,CAAC;EACDC,MAAM,EAAE;IACN;IACA;IACAF,OAAO,EAAE,CAACG,MAAM,CAACC,SAAS;IAC1BH,OAAO,EAAEE,MAAM,CAACC;EAClB,CAAC;EACDC,KAAK,EAAE;IACL;IACAL,OAAO,EAAE,CAAC,YAAY;IACtBC,OAAO,EAAE;EACX,CAAC;EACDK,OAAO,EAAE;IACP;IACAN,OAAO,EAAE,CAAC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AAoBA,CAAChC,KAAc,EAAW;EACrD,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC7B,OAAO,KAAK;EACd;EAGA,OADqB,sCAAsC,CACvCgD,IAAI,CAAChD,KAAK,CAAC,IAAI,CAACmD,KAAK,CAACW,UAAU,CAAC9D,KAAK,CAAC,CAAC;AAC9D","ignoreList":[]}
@@ -0,0 +1,522 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { describe, expect, it } from "vitest";
18
+ import { isInterfaceActionParam, isMediaReference, matchesOntologyDataType } from "./validateAction.js";
19
+ describe("matchesOntologyDataType", () => {
20
+ describe("any type", () => {
21
+ it("should return true for any value", () => {
22
+ const dataType = {
23
+ type: "any"
24
+ };
25
+ expect(matchesOntologyDataType(dataType, undefined)).toBe(true);
26
+ expect(matchesOntologyDataType(dataType, null)).toBe(true);
27
+ expect(matchesOntologyDataType(dataType, "string")).toBe(true);
28
+ expect(matchesOntologyDataType(dataType, 123)).toBe(true);
29
+ expect(matchesOntologyDataType(dataType, true)).toBe(true);
30
+ expect(matchesOntologyDataType(dataType, {})).toBe(true);
31
+ expect(matchesOntologyDataType(dataType, [])).toBe(true);
32
+ });
33
+ });
34
+ describe("boolean type", () => {
35
+ const dataType = {
36
+ type: "boolean"
37
+ };
38
+ it("should return true for boolean values", () => {
39
+ expect(matchesOntologyDataType(dataType, true)).toBe(true);
40
+ expect(matchesOntologyDataType(dataType, false)).toBe(true);
41
+ });
42
+ it("should return false for non-boolean values", () => {
43
+ expect(matchesOntologyDataType(dataType, "true")).toBe(false);
44
+ expect(matchesOntologyDataType(dataType, 1)).toBe(false);
45
+ expect(matchesOntologyDataType(dataType, 0)).toBe(false);
46
+ expect(matchesOntologyDataType(dataType, null)).toBe(false);
47
+ expect(matchesOntologyDataType(dataType, undefined)).toBe(false);
48
+ });
49
+ });
50
+ describe("string type", () => {
51
+ const dataType = {
52
+ type: "string"
53
+ };
54
+ it("should return true for string values", () => {
55
+ expect(matchesOntologyDataType(dataType, "")).toBe(true);
56
+ expect(matchesOntologyDataType(dataType, "hello")).toBe(true);
57
+ expect(matchesOntologyDataType(dataType, "123")).toBe(true);
58
+ });
59
+ it("should return false for non-string values", () => {
60
+ expect(matchesOntologyDataType(dataType, 123)).toBe(false);
61
+ expect(matchesOntologyDataType(dataType, true)).toBe(false);
62
+ expect(matchesOntologyDataType(dataType, null)).toBe(false);
63
+ expect(matchesOntologyDataType(dataType, undefined)).toBe(false);
64
+ expect(matchesOntologyDataType(dataType, {})).toBe(false);
65
+ });
66
+ });
67
+ describe("integer type", () => {
68
+ const dataType = {
69
+ type: "integer"
70
+ };
71
+ it("should return true for valid integer values within bounds", () => {
72
+ expect(matchesOntologyDataType(dataType, 0)).toBe(true);
73
+ expect(matchesOntologyDataType(dataType, 1)).toBe(true);
74
+ expect(matchesOntologyDataType(dataType, -1)).toBe(true);
75
+ expect(matchesOntologyDataType(dataType, 2147483647)).toBe(true); // max int
76
+ expect(matchesOntologyDataType(dataType, -2147483648)).toBe(true); // min int
77
+ });
78
+ it("should return false for non-integer values", () => {
79
+ expect(matchesOntologyDataType(dataType, 1.5)).toBe(false);
80
+ expect(matchesOntologyDataType(dataType, "123")).toBe(false);
81
+ expect(matchesOntologyDataType(dataType, true)).toBe(false);
82
+ expect(matchesOntologyDataType(dataType, null)).toBe(false);
83
+ });
84
+ it("should return false for integers out of bounds", () => {
85
+ expect(matchesOntologyDataType(dataType, 2147483648)).toBe(false); // max + 1
86
+ expect(matchesOntologyDataType(dataType, -2147483649)).toBe(false); // min - 1
87
+ });
88
+ });
89
+ describe("long type", () => {
90
+ const dataType = {
91
+ type: "long"
92
+ };
93
+ it("should return true for valid long values within safe integer bounds", () => {
94
+ expect(matchesOntologyDataType(dataType, 0)).toBe(true);
95
+ expect(matchesOntologyDataType(dataType, Number.MAX_SAFE_INTEGER)).toBe(true);
96
+ expect(matchesOntologyDataType(dataType, Number.MIN_SAFE_INTEGER)).toBe(true);
97
+ });
98
+ it("should return false for non-integer values", () => {
99
+ expect(matchesOntologyDataType(dataType, 1.5)).toBe(false);
100
+ expect(matchesOntologyDataType(dataType, "123")).toBe(false);
101
+ });
102
+ it("should return false for values outside safe integer range", () => {
103
+ expect(matchesOntologyDataType(dataType, Number.MAX_SAFE_INTEGER + 1)).toBe(false);
104
+ expect(matchesOntologyDataType(dataType, Number.MIN_SAFE_INTEGER - 1)).toBe(false);
105
+ });
106
+ });
107
+ describe("double type", () => {
108
+ const dataType = {
109
+ type: "double"
110
+ };
111
+ it("should return true for valid double values", () => {
112
+ expect(matchesOntologyDataType(dataType, 0)).toBe(true);
113
+ expect(matchesOntologyDataType(dataType, 1.5)).toBe(true);
114
+ expect(matchesOntologyDataType(dataType, -1.5)).toBe(true);
115
+ expect(matchesOntologyDataType(dataType, Number.MAX_VALUE)).toBe(true);
116
+ expect(matchesOntologyDataType(dataType, -Number.MAX_VALUE)).toBe(true);
117
+ });
118
+ it("should return false for non-number values", () => {
119
+ expect(matchesOntologyDataType(dataType, "123")).toBe(false);
120
+ expect(matchesOntologyDataType(dataType, true)).toBe(false);
121
+ expect(matchesOntologyDataType(dataType, null)).toBe(false);
122
+ });
123
+ it("should return false for Infinity", () => {
124
+ expect(matchesOntologyDataType(dataType, Infinity)).toBe(false);
125
+ expect(matchesOntologyDataType(dataType, -Infinity)).toBe(false);
126
+ });
127
+ });
128
+ describe("float type", () => {
129
+ const dataType = {
130
+ type: "float"
131
+ };
132
+ it("should return true for valid float values within bounds", () => {
133
+ expect(matchesOntologyDataType(dataType, 0)).toBe(true);
134
+ expect(matchesOntologyDataType(dataType, 1.5)).toBe(true);
135
+ expect(matchesOntologyDataType(dataType, -1.5)).toBe(true);
136
+ expect(matchesOntologyDataType(dataType, 3.4028235e38)).toBe(true);
137
+ expect(matchesOntologyDataType(dataType, -3.4028235e38)).toBe(true);
138
+ });
139
+ it("should return false for values outside float bounds", () => {
140
+ expect(matchesOntologyDataType(dataType, 3.5e38)).toBe(false);
141
+ expect(matchesOntologyDataType(dataType, -3.5e38)).toBe(false);
142
+ });
143
+ });
144
+ describe("byte type", () => {
145
+ const dataType = {
146
+ type: "byte"
147
+ };
148
+ it("should return true for valid byte values", () => {
149
+ expect(matchesOntologyDataType(dataType, 0)).toBe(true);
150
+ expect(matchesOntologyDataType(dataType, 127)).toBe(true);
151
+ expect(matchesOntologyDataType(dataType, -128)).toBe(true);
152
+ });
153
+ it("should return false for values outside byte bounds", () => {
154
+ expect(matchesOntologyDataType(dataType, 128)).toBe(false);
155
+ expect(matchesOntologyDataType(dataType, -129)).toBe(false);
156
+ });
157
+ it("should return false for non-integer values", () => {
158
+ expect(matchesOntologyDataType(dataType, 1.5)).toBe(true); // Note: isInBounds doesn't check for integers for byte
159
+ });
160
+ });
161
+ describe("short type", () => {
162
+ const dataType = {
163
+ type: "short"
164
+ };
165
+ it("should return true for valid short values", () => {
166
+ expect(matchesOntologyDataType(dataType, 0)).toBe(true);
167
+ expect(matchesOntologyDataType(dataType, 32767)).toBe(true);
168
+ expect(matchesOntologyDataType(dataType, -32768)).toBe(true);
169
+ });
170
+ it("should return false for values outside short bounds", () => {
171
+ expect(matchesOntologyDataType(dataType, 32768)).toBe(false);
172
+ expect(matchesOntologyDataType(dataType, -32769)).toBe(false);
173
+ });
174
+ });
175
+ describe("date type", () => {
176
+ const dataType = {
177
+ type: "date"
178
+ };
179
+ it("should return true for valid date strings", () => {
180
+ expect(matchesOntologyDataType(dataType, "2025-01-15")).toBe(true);
181
+ expect(matchesOntologyDataType(dataType, "2000-12-31")).toBe(true);
182
+ expect(matchesOntologyDataType(dataType, "1970-01-01")).toBe(true);
183
+ });
184
+ it("should return false for invalid date strings", () => {
185
+ expect(matchesOntologyDataType(dataType, "2025-13-01")).toBe(false); // invalid month
186
+ expect(matchesOntologyDataType(dataType, "2025-01-32")).toBe(false); // invalid day
187
+ expect(matchesOntologyDataType(dataType, "2025/01/15")).toBe(false); // wrong format
188
+ expect(matchesOntologyDataType(dataType, "01-15-2025")).toBe(false); // wrong format
189
+ expect(matchesOntologyDataType(dataType, "not a date")).toBe(false);
190
+ });
191
+ it("should return false for non-string values", () => {
192
+ expect(matchesOntologyDataType(dataType, 123)).toBe(false);
193
+ expect(matchesOntologyDataType(dataType, new Date())).toBe(false);
194
+ });
195
+ });
196
+ describe("timestamp type", () => {
197
+ const dataType = {
198
+ type: "timestamp"
199
+ };
200
+ it("should return true for valid timestamp strings", () => {
201
+ expect(matchesOntologyDataType(dataType, "2025-01-15T10:30:00Z")).toBe(true);
202
+ expect(matchesOntologyDataType(dataType, "2025-01-15T10:30:00.123Z")).toBe(true);
203
+ expect(matchesOntologyDataType(dataType, "2025-01-15")).toBe(true);
204
+ });
205
+ it("should return false for invalid timestamp strings", () => {
206
+ expect(matchesOntologyDataType(dataType, "not a timestamp")).toBe(false);
207
+ expect(matchesOntologyDataType(dataType, "")).toBe(false);
208
+ });
209
+ it("should return false for non-string values", () => {
210
+ expect(matchesOntologyDataType(dataType, 123)).toBe(false);
211
+ expect(matchesOntologyDataType(dataType, new Date())).toBe(false);
212
+ });
213
+ });
214
+ describe("decimal type", () => {
215
+ const dataType = {
216
+ type: "decimal"
217
+ };
218
+ it("should return true for valid decimal strings", () => {
219
+ expect(matchesOntologyDataType(dataType, "0")).toBe(true);
220
+ expect(matchesOntologyDataType(dataType, "123")).toBe(true);
221
+ expect(matchesOntologyDataType(dataType, "123.456")).toBe(true);
222
+ expect(matchesOntologyDataType(dataType, "-123.456")).toBe(true);
223
+ expect(matchesOntologyDataType(dataType, "+123.456")).toBe(true);
224
+ expect(matchesOntologyDataType(dataType, ".5")).toBe(true);
225
+ expect(matchesOntologyDataType(dataType, "-.5")).toBe(true);
226
+ expect(matchesOntologyDataType(dataType, "123.")).toBe(true);
227
+ });
228
+ it("should return true for valid decimal strings with scientific notation", () => {
229
+ expect(matchesOntologyDataType(dataType, "1E10")).toBe(true);
230
+ expect(matchesOntologyDataType(dataType, "1.5E10")).toBe(true);
231
+ expect(matchesOntologyDataType(dataType, "1.5E+10")).toBe(true);
232
+ expect(matchesOntologyDataType(dataType, "1.5E-10")).toBe(true);
233
+ expect(matchesOntologyDataType(dataType, "-1.5E10")).toBe(true);
234
+ });
235
+ it("should return false for invalid decimal strings", () => {
236
+ expect(matchesOntologyDataType(dataType, "abc")).toBe(false);
237
+ expect(matchesOntologyDataType(dataType, "12.34.56")).toBe(false);
238
+ expect(matchesOntologyDataType(dataType, "1.2.3E10")).toBe(false);
239
+ expect(matchesOntologyDataType(dataType, "")).toBe(false);
240
+ expect(matchesOntologyDataType(dataType, "E10")).toBe(false);
241
+ expect(matchesOntologyDataType(dataType, "1E")).toBe(false);
242
+ expect(matchesOntologyDataType(dataType, "1e10")).toBe(false);
243
+ });
244
+ it("should return false for non-string values", () => {
245
+ expect(matchesOntologyDataType(dataType, 123.456)).toBe(false);
246
+ expect(matchesOntologyDataType(dataType, 123)).toBe(false);
247
+ expect(matchesOntologyDataType(dataType, true)).toBe(false);
248
+ expect(matchesOntologyDataType(dataType, null)).toBe(false);
249
+ expect(matchesOntologyDataType(dataType, undefined)).toBe(false);
250
+ expect(matchesOntologyDataType(dataType, {})).toBe(false);
251
+ });
252
+ });
253
+ describe("marking type", () => {
254
+ const dataType = {
255
+ type: "marking"
256
+ };
257
+ it("should return true for string values", () => {
258
+ expect(matchesOntologyDataType(dataType, "marking1")).toBe(true);
259
+ expect(matchesOntologyDataType(dataType, "")).toBe(true);
260
+ });
261
+ it("should return false for non-string values", () => {
262
+ expect(matchesOntologyDataType(dataType, 123)).toBe(false);
263
+ expect(matchesOntologyDataType(dataType, null)).toBe(false);
264
+ });
265
+ });
266
+ describe("object type", () => {
267
+ const dataType = {
268
+ type: "object",
269
+ objectApiName: "Employee",
270
+ objectTypeApiName: "Employee"
271
+ };
272
+ it("should return true for string (RID) values", () => {
273
+ expect(matchesOntologyDataType(dataType, "ri.object.123")).toBe(true);
274
+ expect(matchesOntologyDataType(dataType, "someId")).toBe(true);
275
+ });
276
+ it("should return true for objects with $primaryKey", () => {
277
+ expect(matchesOntologyDataType(dataType, {
278
+ $primaryKey: "123"
279
+ })).toBe(true);
280
+ expect(matchesOntologyDataType(dataType, {
281
+ $primaryKey: "123",
282
+ name: "test"
283
+ })).toBe(true);
284
+ });
285
+ it("should return false for objects without $primaryKey", () => {
286
+ expect(matchesOntologyDataType(dataType, {
287
+ name: "test"
288
+ })).toBe(false);
289
+ expect(matchesOntologyDataType(dataType, {})).toBe(false);
290
+ });
291
+ it("should return false for other value types", () => {
292
+ expect(matchesOntologyDataType(dataType, 123)).toBe(false);
293
+ expect(matchesOntologyDataType(dataType, true)).toBe(false);
294
+ expect(matchesOntologyDataType(dataType, null)).toBe(false);
295
+ });
296
+ });
297
+ describe("objectSet type", () => {
298
+ const dataType = {
299
+ type: "objectSet"
300
+ };
301
+ it("should return true for RID strings", () => {
302
+ expect(matchesOntologyDataType(dataType, "ri.objectSet.123")).toBe(true);
303
+ expect(matchesOntologyDataType(dataType, "ri.anything.456")).toBe(true);
304
+ });
305
+ it("should return true for objects with objectSet property", () => {
306
+ expect(matchesOntologyDataType(dataType, {
307
+ objectSet: "definition"
308
+ })).toBe(true);
309
+ });
310
+ it("should return false for non-RID strings", () => {
311
+ expect(matchesOntologyDataType(dataType, "not a rid")).toBe(false);
312
+ expect(matchesOntologyDataType(dataType, "objectSet")).toBe(false);
313
+ });
314
+ it("should return false for objects without objectSet property", () => {
315
+ expect(matchesOntologyDataType(dataType, {
316
+ name: "test"
317
+ })).toBe(false);
318
+ });
319
+ });
320
+ describe("array type", () => {
321
+ it("should return true for arrays with matching item types", () => {
322
+ const dataType = {
323
+ type: "array",
324
+ itemType: {
325
+ type: "string"
326
+ }
327
+ };
328
+ expect(matchesOntologyDataType(dataType, [])).toBe(true);
329
+ expect(matchesOntologyDataType(dataType, ["a", "b", "c"])).toBe(true);
330
+ });
331
+ it("should return false for arrays with non-matching item types", () => {
332
+ const dataType = {
333
+ type: "array",
334
+ itemType: {
335
+ type: "string"
336
+ }
337
+ };
338
+ expect(matchesOntologyDataType(dataType, [1, 2, 3])).toBe(false);
339
+ expect(matchesOntologyDataType(dataType, ["a", 1, "c"])).toBe(false);
340
+ });
341
+ it("should work with nested arrays", () => {
342
+ const dataType = {
343
+ type: "array",
344
+ itemType: {
345
+ type: "array",
346
+ itemType: {
347
+ type: "integer"
348
+ }
349
+ }
350
+ };
351
+ expect(matchesOntologyDataType(dataType, [[1, 2], [3, 4]])).toBe(true);
352
+ expect(matchesOntologyDataType(dataType, [[1, 2], ["a", "b"]])).toBe(false);
353
+ });
354
+ it("should return false for non-array values", () => {
355
+ const dataType = {
356
+ type: "array",
357
+ itemType: {
358
+ type: "string"
359
+ }
360
+ };
361
+ expect(matchesOntologyDataType(dataType, "not an array")).toBe(false);
362
+ expect(matchesOntologyDataType(dataType, 123)).toBe(false);
363
+ expect(matchesOntologyDataType(dataType, {
364
+ length: 0
365
+ })).toBe(false);
366
+ });
367
+ });
368
+ describe("cipherText type", () => {
369
+ const dataType = {
370
+ type: "cipherText"
371
+ };
372
+ it("should return true for valid CIPHER format", () => {
373
+ expect(matchesOntologyDataType(dataType, "CIPHER::ri.channel.123::encrypted::CIPHER")).toBe(true);
374
+ });
375
+ it("should return true for valid BELLASO format", () => {
376
+ expect(matchesOntologyDataType(dataType, "BELLASO::ri.channel.123::encrypted::BELLASO")).toBe(true);
377
+ });
378
+ it("should return true for valid BELLASO format without suffix", () => {
379
+ expect(matchesOntologyDataType(dataType, "BELLASO::ri.channel.123::encrypted")).toBe(true);
380
+ });
381
+ it("should return false for invalid cipher format", () => {
382
+ expect(matchesOntologyDataType(dataType, "CIPHER::channel::data")).toBe(false); // missing ri. prefix
383
+ expect(matchesOntologyDataType(dataType, "CIPHER::ri.channel.123::")).toBe(false); // empty encrypted value
384
+ expect(matchesOntologyDataType(dataType, "INVALID::ri.channel.123::data::INVALID")).toBe(false);
385
+ });
386
+ it("should return false for non-string values", () => {
387
+ expect(matchesOntologyDataType(dataType, 123)).toBe(false);
388
+ expect(matchesOntologyDataType(dataType, null)).toBe(false);
389
+ });
390
+ });
391
+ describe("binary type", () => {
392
+ const dataType = {
393
+ type: "binary"
394
+ };
395
+ it("should throw an error", () => {
396
+ expect(() => matchesOntologyDataType(dataType, "data")).toThrow("validateDataType: binary not implemented yet.");
397
+ });
398
+ });
399
+ describe("map type", () => {
400
+ const dataType = {
401
+ type: "map",
402
+ keyType: {
403
+ type: "string"
404
+ },
405
+ valueType: {
406
+ type: "integer"
407
+ }
408
+ };
409
+ it("should throw an error", () => {
410
+ expect(() => matchesOntologyDataType(dataType, {})).toThrow("matchesOntologyDataType: map not implemented yet.");
411
+ });
412
+ });
413
+ describe("set type", () => {
414
+ const dataType = {
415
+ type: "set",
416
+ itemType: {
417
+ type: "string"
418
+ }
419
+ };
420
+ it("should throw an error", () => {
421
+ expect(() => matchesOntologyDataType(dataType, new Set())).toThrow("matchesOntologyDataType: set not implemented yet.");
422
+ });
423
+ });
424
+ describe("struct type", () => {
425
+ const dataType = {
426
+ type: "struct",
427
+ fields: []
428
+ };
429
+ it("should throw an error", () => {
430
+ expect(() => matchesOntologyDataType(dataType, {})).toThrow("matchesOntologyDataType: struct not implemented yet.");
431
+ });
432
+ });
433
+ describe("unsupported type", () => {
434
+ const dataType = {
435
+ type: "unsupported",
436
+ unsupportedType: "someCustomType"
437
+ };
438
+ it("should throw an error", () => {
439
+ expect(() => matchesOntologyDataType(dataType, "anything")).toThrow("matchesOntologyDataType: unsupported not implemented yet.");
440
+ });
441
+ });
442
+ });
443
+ describe("isMediaReference", () => {
444
+ it("should return true for valid MediaReference objects", () => {
445
+ expect(isMediaReference({
446
+ mimeType: "image/png",
447
+ reference: {
448
+ type: "mediaSetViewItem",
449
+ mediaSetViewItem: {
450
+ mediaSetRid: "ri.mediaset.123",
451
+ mediaSetViewRid: "ri.mediasetview.456",
452
+ mediaItemRid: "ri.mediaitem.789"
453
+ }
454
+ }
455
+ })).toBe(true);
456
+ });
457
+ it("should return false for objects missing required properties", () => {
458
+ expect(isMediaReference({
459
+ mimeType: "image/png"
460
+ })).toBe(false);
461
+ expect(isMediaReference({
462
+ reference: {
463
+ type: "mediaSetViewItem",
464
+ mediaSetViewItem: {}
465
+ }
466
+ })).toBe(false);
467
+ });
468
+ it("should return false for objects with incorrect reference type", () => {
469
+ expect(isMediaReference({
470
+ mimeType: "image/png",
471
+ reference: {
472
+ type: "wrongType",
473
+ mediaSetViewItem: {
474
+ mediaSetRid: "ri.mediaset.123",
475
+ mediaSetViewRid: "ri.mediasetview.456",
476
+ mediaItemRid: "ri.mediaitem.789"
477
+ }
478
+ }
479
+ })).toBe(false);
480
+ });
481
+ });
482
+ describe("isInterfaceActionParam", () => {
483
+ it("should return true for valid interface action params with string primary key", () => {
484
+ expect(isInterfaceActionParam({
485
+ objectTypeApiName: "Employee",
486
+ primaryKeyValue: "emp-123"
487
+ })).toBe(true);
488
+ });
489
+ it("should return true for valid interface action params with number primary key", () => {
490
+ expect(isInterfaceActionParam({
491
+ objectTypeApiName: "Employee",
492
+ primaryKeyValue: 123
493
+ })).toBe(true);
494
+ });
495
+ it("should return true for valid interface action params with boolean primary key", () => {
496
+ expect(isInterfaceActionParam({
497
+ objectTypeApiName: "Employee",
498
+ primaryKeyValue: true
499
+ })).toBe(true);
500
+ });
501
+ it("should return false for objects missing objectTypeApiName", () => {
502
+ expect(isInterfaceActionParam({
503
+ primaryKeyValue: "123"
504
+ })).toBe(false);
505
+ });
506
+ it("should return false for objects missing primaryKeyValue", () => {
507
+ expect(isInterfaceActionParam({
508
+ objectTypeApiName: "Employee"
509
+ })).toBe(false);
510
+ });
511
+ it("should return false for objects with invalid primaryKeyValue type", () => {
512
+ expect(isInterfaceActionParam({
513
+ objectTypeApiName: "Employee",
514
+ primaryKeyValue: {}
515
+ })).toBe(false);
516
+ expect(isInterfaceActionParam({
517
+ objectTypeApiName: "Employee",
518
+ primaryKeyValue: []
519
+ })).toBe(false);
520
+ });
521
+ });
522
+ //# sourceMappingURL=validateAction.test.js.map