@valerypopoff/rivet2-evaluations 2.4.0 → 2.6.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.
@@ -28,11 +28,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
33
  EvaluationGraphExecutionError: () => EvaluationGraphExecutionError,
34
34
  InMemoryEvaluationRunStore: () => InMemoryEvaluationRunStore,
35
35
  LEGACY_EVALUATOR_INPUT_IDS: () => LEGACY_EVALUATOR_INPUT_IDS,
36
+ applyEvaluationLibraryMutation: () => applyEvaluationLibraryMutation,
36
37
  areEvaluationDataTypesCompatible: () => areEvaluationDataTypesCompatible,
37
38
  assertEvaluationDatasetSnapshot: () => assertEvaluationDatasetSnapshot,
38
39
  assertEvaluationDatasetValuesMatchDeclaredTypes: () => assertEvaluationDatasetValuesMatchDeclaredTypes,
@@ -51,12 +52,16 @@ __export(index_exports, {
51
52
  deserializeEvaluationProjectData: () => deserializeEvaluationProjectData,
52
53
  deserializeEvaluationProjectDataFromString: () => deserializeEvaluationProjectDataFromString,
53
54
  deserializeEvaluationSuiteBundleJson: () => deserializeEvaluationSuiteBundleJson,
55
+ diffEvaluationLibraryMutation: () => diffEvaluationLibraryMutation,
54
56
  evaluateAssertion: () => evaluateAssertion,
55
57
  evaluateThresholdResults: () => evaluateThresholdResults,
58
+ evaluationLibraryValueEquals: () => evaluationLibraryValueEquals,
56
59
  finalizeEvaluationRecordingRetention: () => finalizeEvaluationRecordingRetention,
57
60
  finalizeEvaluationRun: () => finalizeEvaluationRun,
58
61
  fingerprint: () => fingerprint,
59
62
  fingerprintEvaluationDataset: () => fingerprintEvaluationDataset,
63
+ getEvaluationLibraryResource: () => getEvaluationLibraryResource,
64
+ getEvaluationSuiteBundle: () => getEvaluationSuiteBundle,
60
65
  getEvaluationSuiteMode: () => getEvaluationSuiteMode,
61
66
  getEvaluationTopLevelOutputId: () => getEvaluationTopLevelOutputId,
62
67
  hasAuthoritativeEvaluationCriteria: () => hasAuthoritativeEvaluationCriteria,
@@ -88,7 +93,7 @@ __export(index_exports, {
88
93
  validateEvaluationDataset: () => validateEvaluationDataset,
89
94
  validateEvaluationDatasetForTransfer: () => validateEvaluationDatasetForTransfer
90
95
  });
91
- module.exports = __toCommonJS(index_exports);
96
+ module.exports = __toCommonJS(src_exports);
92
97
 
93
98
  // src/types.ts
94
99
  var EvaluationGraphExecutionError = class extends Error {
@@ -3360,11 +3365,111 @@ function deserializeEvaluationSuiteBundleJson(source, scope) {
3360
3365
  }
3361
3366
  };
3362
3367
  }
3368
+
3369
+ // src/librarySync.ts
3370
+ function evaluationLibraryValueEquals(left, right) {
3371
+ if (left === void 0 || right === void 0) return left === right;
3372
+ return canonicalStringify(left) === canonicalStringify(right);
3373
+ }
3374
+ function getEvaluationSuiteBundle(library, id) {
3375
+ const suite = library.data.suites.find((candidate) => candidate.id === id);
3376
+ if (!suite) return void 0;
3377
+ return {
3378
+ suite,
3379
+ baselines: library.data.baselines.filter((baseline) => baseline.suiteId === id)
3380
+ };
3381
+ }
3382
+ function getEvaluationLibraryResource(library, kind, id) {
3383
+ if (kind === "suite") return { kind, id, value: getEvaluationSuiteBundle(library, id) };
3384
+ return { kind, id, value: library.datasets.find((dataset) => dataset.id === id) };
3385
+ }
3386
+ function resourceIds(library, kind) {
3387
+ return new Set(kind === "suite" ? library.data.suites.map((suite) => suite.id) : library.datasets.map((dataset) => dataset.id));
3388
+ }
3389
+ function diffEvaluationLibraryMutation(previous, next, versions) {
3390
+ const changes = [];
3391
+ for (const kind of ["dataset", "suite"]) {
3392
+ const ids = /* @__PURE__ */ new Set([...resourceIds(previous, kind), ...resourceIds(next, kind)]);
3393
+ for (const id of [...ids].sort()) {
3394
+ if (kind === "suite") {
3395
+ const before = getEvaluationSuiteBundle(previous, id);
3396
+ const after = getEvaluationSuiteBundle(next, id);
3397
+ if (evaluationLibraryValueEquals(before, after)) continue;
3398
+ const currentVersion = versions.suites[id];
3399
+ if (before !== void 0 && currentVersion === void 0) {
3400
+ throw new Error(`The suite "${id}" has no synchronization version.`);
3401
+ }
3402
+ const expectedVersion = before === void 0 ? null : currentVersion;
3403
+ if (after === void 0) {
3404
+ changes.push({ kind: "delete-suite", id, expectedVersion });
3405
+ } else {
3406
+ changes.push({
3407
+ kind: "put-suite",
3408
+ id,
3409
+ expectedVersion,
3410
+ suite: after.suite,
3411
+ baselines: after.baselines
3412
+ });
3413
+ }
3414
+ } else {
3415
+ const before = previous.datasets.find((dataset) => dataset.id === id);
3416
+ const after = next.datasets.find((dataset) => dataset.id === id);
3417
+ if (evaluationLibraryValueEquals(before, after)) continue;
3418
+ const currentVersion = versions.datasets[id];
3419
+ if (before !== void 0 && currentVersion === void 0) {
3420
+ throw new Error(`The dataset "${id}" has no synchronization version.`);
3421
+ }
3422
+ const expectedVersion = before === void 0 ? null : currentVersion;
3423
+ if (after === void 0) {
3424
+ changes.push({ kind: "delete-dataset", id, expectedVersion });
3425
+ } else {
3426
+ changes.push({ kind: "put-dataset", id, expectedVersion, dataset: after });
3427
+ }
3428
+ }
3429
+ }
3430
+ }
3431
+ return changes.length === 0 ? void 0 : { changes };
3432
+ }
3433
+ function replaceById(items, value) {
3434
+ const index = items.findIndex((item) => item.id === value.id);
3435
+ if (index === -1) return [...items, value];
3436
+ return items.map((item) => item.id === value.id ? value : item);
3437
+ }
3438
+ function applyEvaluationLibraryMutation(library, mutation) {
3439
+ let suites = library.data.suites;
3440
+ let baselines = library.data.baselines;
3441
+ let datasets = library.datasets;
3442
+ for (const change of mutation.changes) {
3443
+ switch (change.kind) {
3444
+ case "put-suite":
3445
+ suites = replaceById(suites, change.suite);
3446
+ baselines = [...baselines.filter((baseline) => baseline.suiteId !== change.id), ...change.baselines];
3447
+ break;
3448
+ case "delete-suite":
3449
+ suites = suites.filter((suite) => suite.id !== change.id);
3450
+ baselines = baselines.filter((baseline) => baseline.suiteId !== change.id);
3451
+ break;
3452
+ case "put-dataset":
3453
+ datasets = replaceById(datasets, change.dataset);
3454
+ break;
3455
+ case "delete-dataset":
3456
+ datasets = datasets.filter((dataset) => dataset.id !== change.id);
3457
+ break;
3458
+ }
3459
+ }
3460
+ return normalizeEvaluationLibrary({
3461
+ version: 1,
3462
+ data: { version: 1, suites, baselines },
3463
+ datasets,
3464
+ migratedLegacyProjectIds: library.migratedLegacyProjectIds
3465
+ });
3466
+ }
3363
3467
  // Annotate the CommonJS export names for ESM import in node:
3364
3468
  0 && (module.exports = {
3365
3469
  EvaluationGraphExecutionError,
3366
3470
  InMemoryEvaluationRunStore,
3367
3471
  LEGACY_EVALUATOR_INPUT_IDS,
3472
+ applyEvaluationLibraryMutation,
3368
3473
  areEvaluationDataTypesCompatible,
3369
3474
  assertEvaluationDatasetSnapshot,
3370
3475
  assertEvaluationDatasetValuesMatchDeclaredTypes,
@@ -3383,12 +3488,16 @@ function deserializeEvaluationSuiteBundleJson(source, scope) {
3383
3488
  deserializeEvaluationProjectData,
3384
3489
  deserializeEvaluationProjectDataFromString,
3385
3490
  deserializeEvaluationSuiteBundleJson,
3491
+ diffEvaluationLibraryMutation,
3386
3492
  evaluateAssertion,
3387
3493
  evaluateThresholdResults,
3494
+ evaluationLibraryValueEquals,
3388
3495
  finalizeEvaluationRecordingRetention,
3389
3496
  finalizeEvaluationRun,
3390
3497
  fingerprint,
3391
3498
  fingerprintEvaluationDataset,
3499
+ getEvaluationLibraryResource,
3500
+ getEvaluationSuiteBundle,
3392
3501
  getEvaluationSuiteMode,
3393
3502
  getEvaluationTopLevelOutputId,
3394
3503
  hasAuthoritativeEvaluationCriteria,