MCPcopy Create free account
hub / github.com/vercel/vercel / applySegmentOperationsForMock

Function applySegmentOperationsForMock

packages/cli/test/mocks/flags.ts:595–621  ·  view source on GitHub ↗
(
  data: Segment['data'],
  operations: SegmentMembershipOperation[]
)

Source from the content-addressed store, hash-verified

593}
594
595function applySegmentOperationsForMock(
596 data: Segment['data'],
597 operations: SegmentMembershipOperation[]
598): Segment['data'] {
599 const next: Segment['data'] = {
600 rules: structuredClone(data.rules ?? []),
601 include: structuredClone(data.include ?? {}),
602 exclude: structuredClone(data.exclude ?? {}),
603 };
604
605 for (const operation of operations) {
606 const map = next[operation.field] ?? {};
607 const entityValues = map[operation.entity] ?? {};
608 const values = entityValues[operation.attribute] ?? [];
609 if (operation.action === 'add') {
610 entityValues[operation.attribute] = values.concat(operation.value);
611 } else {
612 entityValues[operation.attribute] = values.filter(
613 value => value.value !== operation.value.value
614 );
615 }
616 map[operation.entity] = entityValues;
617 next[operation.field] = map;
618 }
619
620 return next;
621}

Callers 1

useFlagsFunction · 0.85

Calls 1

filterMethod · 0.80

Tested by

no test coverage detected