@osdk/faux 0.4.0-beta.2 → 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.
@@ -918,6 +918,40 @@ function parseLocator(locator) {
918
918
  }
919
919
 
920
920
  // src/FauxFoundry/validateAction.ts
921
+ var NUMERIC_LITERAL_BOUNDS = {
922
+ byte: {
923
+ // Java min/max byte bounds
924
+ minimum: -128,
925
+ maximum: 127
926
+ },
927
+ double: {
928
+ // These numbers are smaller than the actual min/max of a java double,
929
+ // but going higher will require using BigInt in our input fields.
930
+ minimum: -Number.MAX_VALUE,
931
+ maximum: Number.MAX_VALUE
932
+ },
933
+ float: {
934
+ // Java min/max float bounds
935
+ minimum: -34028235e31,
936
+ maximum: 34028235e31
937
+ },
938
+ integer: {
939
+ // Java min/max integer bounds
940
+ minimum: -2147483648,
941
+ maximum: 2147483647
942
+ },
943
+ long: {
944
+ // These numbers are smaller than the actual min/max of a java long,
945
+ // but going higher will require using BigInt in our input fields.
946
+ minimum: Number.MIN_SAFE_INTEGER,
947
+ maximum: Number.MAX_SAFE_INTEGER
948
+ },
949
+ short: {
950
+ // Java min/max short bounds
951
+ minimum: -32768,
952
+ maximum: 32767
953
+ }
954
+ };
921
955
  function validateAction(payload, def, dataStore) {
922
956
  const ret = {
923
957
  parameters: {},
@@ -1087,39 +1121,39 @@ function matchesOntologyDataType(odt, value) {
1087
1121
  case "boolean":
1088
1122
  return typeof value === "boolean";
1089
1123
  case "byte":
1090
- throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1124
+ return typeof value === "number" && isInBounds(value, NUMERIC_LITERAL_BOUNDS.byte);
1091
1125
  case "cipherText":
1092
- throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1126
+ return isValidCipherText(value);
1093
1127
  case "date":
1094
- throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1128
+ return isValidDateString(value);
1095
1129
  case "decimal":
1096
- throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1130
+ return isValidDecimalString(value);
1097
1131
  case "double":
1098
- return typeof value === "number";
1132
+ return typeof value === "number" && isInBounds(value, NUMERIC_LITERAL_BOUNDS.double);
1099
1133
  case "float":
1100
- throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1134
+ return typeof value === "number" && isInBounds(value, NUMERIC_LITERAL_BOUNDS.float);
1101
1135
  case "integer":
1102
- return typeof value === "number" && Number.isInteger(value);
1136
+ return typeof value === "number" && Number.isInteger(value) && isInBounds(value, NUMERIC_LITERAL_BOUNDS.integer);
1103
1137
  case "long":
1104
- throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1138
+ return typeof value === "number" && Number.isInteger(value) && isInBounds(value, NUMERIC_LITERAL_BOUNDS.long);
1105
1139
  case "map":
1106
1140
  throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1107
1141
  case "marking":
1108
- throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1142
+ return typeof value === "string";
1109
1143
  case "object":
1110
1144
  return typeof value === "string" || value != null && typeof value === "object" && "$primaryKey" in value;
1111
1145
  case "objectSet":
1112
- throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1146
+ return typeof value === "string" && value.startsWith("ri.") || value != null && typeof value === "object" && "objectSet" in value;
1113
1147
  case "set":
1114
1148
  throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1115
1149
  case "short":
1116
- throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1150
+ return typeof value === "number" && isInBounds(value, NUMERIC_LITERAL_BOUNDS.short);
1117
1151
  case "string":
1118
1152
  return typeof value === "string";
1119
1153
  case "struct":
1120
1154
  throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1121
1155
  case "timestamp":
1122
- throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1156
+ return isValidTimestampString(value);
1123
1157
  case "unsupported":
1124
1158
  throw new Error(`matchesOntologyDataType: ${odt.type} not implemented yet.`);
1125
1159
  default:
@@ -1132,6 +1166,46 @@ function isMediaReference(o) {
1132
1166
  function isInterfaceActionParam(value) {
1133
1167
  return typeof value === "object" && "objectTypeApiName" in value && typeof value.objectTypeApiName === "string" && "primaryKeyValue" in value && (typeof value.primaryKeyValue === "string" || typeof value.primaryKeyValue === "number" || typeof value.primaryKeyValue === "boolean");
1134
1168
  }
1169
+ function isInBounds(value, bounds) {
1170
+ return bounds.minimum <= value && value <= bounds.maximum;
1171
+ }
1172
+ function isValidDateString(value) {
1173
+ if (typeof value !== "string") {
1174
+ return false;
1175
+ }
1176
+ const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
1177
+ if (!dateRegex.test(value)) {
1178
+ return false;
1179
+ }
1180
+ const date = new Date(value);
1181
+ return !isNaN(date.getTime()) && date.toISOString().startsWith(value);
1182
+ }
1183
+ function isValidTimestampString(value) {
1184
+ return typeof value === "string" && !isNaN(new Date(value).getTime());
1185
+ }
1186
+ function isValidCipherText(value) {
1187
+ if (typeof value !== "string") {
1188
+ return false;
1189
+ }
1190
+ const parts = value.split("::");
1191
+ if (!(isValidCipherAffix(parts, "CIPHER") || isValidCipherAffix(parts, "BELLASO") || isValidCipherAffix(parts, "BELLASO", true))) {
1192
+ return false;
1193
+ }
1194
+ const channelRid = parts[1];
1195
+ const encryptedValue = parts[2];
1196
+ return channelRid.startsWith("ri.") && encryptedValue !== "";
1197
+ }
1198
+ function isValidCipherAffix(parts, affix, prefixOnly = false) {
1199
+ const totalParts = prefixOnly ? 3 : 4;
1200
+ return parts.length === totalParts && parts[0] === affix && (prefixOnly || parts[3] === affix);
1201
+ }
1202
+ function isValidDecimalString(value) {
1203
+ if (typeof value !== "string") {
1204
+ return false;
1205
+ }
1206
+ const decimalRegex = /^[+-]?(\d+\.?\d*|\.\d+)(E[+-]?\d+)?$/;
1207
+ return decimalRegex.test(value) && !isNaN(parseFloat(value));
1208
+ }
1135
1209
 
1136
1210
  // src/FauxFoundry/FauxDataStore.ts
1137
1211
  var FauxDataStore = class {