@lucern/confidence 0.3.0-alpha.1 → 0.3.0-alpha.11

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/dist/v1/index.js CHANGED
@@ -1125,6 +1125,9 @@ function generateContractId() {
1125
1125
  }
1126
1126
  return `contract-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
1127
1127
  }
1128
+ function isRecord(value) {
1129
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1130
+ }
1128
1131
  function deriveContractStatus(result, currentStatus) {
1129
1132
  if (currentStatus === "archived") {
1130
1133
  return currentStatus;
@@ -1266,18 +1269,17 @@ function pickFiniteNumber(config, keys) {
1266
1269
  return void 0;
1267
1270
  }
1268
1271
  function getEvaluatorInputRecord(inputData, nestedKey) {
1269
- if (!inputData || typeof inputData !== "object") {
1272
+ if (!isRecord(inputData)) {
1270
1273
  return {};
1271
1274
  }
1272
- const root = inputData;
1273
- const nested = root[nestedKey];
1274
- if (nested && typeof nested === "object") {
1275
+ const nested = inputData[nestedKey];
1276
+ if (isRecord(nested)) {
1275
1277
  return nested;
1276
1278
  }
1277
- return root;
1279
+ return inputData;
1278
1280
  }
1279
1281
  function parseEvidentialEvaluatorConfig(value) {
1280
- if (!value || typeof value !== "object") {
1282
+ if (!isRecord(value)) {
1281
1283
  throw new Error(
1282
1284
  "Evidential contracts require condition.evaluatorConfig with metric/operator/threshold."
1283
1285
  );
@@ -1295,7 +1297,7 @@ function parseEvidentialEvaluatorConfig(value) {
1295
1297
  if (typeof threshold !== "number" || !Number.isFinite(threshold)) {
1296
1298
  throw new Error("Evidential contracts require a numeric threshold.");
1297
1299
  }
1298
- const actionParams = config.actionParams && typeof config.actionParams === "object" && config.actionParams !== null ? config.actionParams : void 0;
1300
+ const actionParams = isRecord(config.actionParams) ? config.actionParams : void 0;
1299
1301
  return {
1300
1302
  metric,
1301
1303
  operator,
@@ -1344,7 +1346,7 @@ function buildEvidentialRationale(args) {
1344
1346
  return `${clause}; comparison ${args.comparisonSatisfied ? "passed" : "failed"}, resulting in ${args.result}.`;
1345
1347
  }
1346
1348
  function parseMetricCheckerConfig(value) {
1347
- if (!value || typeof value !== "object") {
1349
+ if (!isRecord(value)) {
1348
1350
  throw new Error(
1349
1351
  "metric_checker requires condition.evaluatorConfig with observedValue/operator/threshold."
1350
1352
  );
@@ -1361,7 +1363,7 @@ function parseMetricCheckerConfig(value) {
1361
1363
  };
1362
1364
  }
1363
1365
  function parseReferenceCheckCounterConfig(value) {
1364
- if (!value || typeof value !== "object") {
1366
+ if (!isRecord(value)) {
1365
1367
  throw new Error(
1366
1368
  "reference_check_counter requires condition.evaluatorConfig with tag/operator/threshold."
1367
1369
  );
@@ -1384,7 +1386,7 @@ function parseReferenceCheckCounterConfig(value) {
1384
1386
  };
1385
1387
  }
1386
1388
  function parseTemporalDeadlineConfig(value) {
1387
- if (!value || typeof value !== "object") {
1389
+ if (!isRecord(value)) {
1388
1390
  return {};
1389
1391
  }
1390
1392
  const config = value;
@@ -1398,7 +1400,7 @@ function parseTemporalDeadlineConfig(value) {
1398
1400
  };
1399
1401
  }
1400
1402
  function parseMarketIndexComparatorConfig(value) {
1401
- if (!value || typeof value !== "object") {
1403
+ if (!isRecord(value)) {
1402
1404
  throw new Error(
1403
1405
  "market_index_comparator requires condition.evaluatorConfig with subjectValue/benchmarkValue/operator/threshold."
1404
1406
  );