Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ describe('CacheInitializer', () => {

const flag1Update = result.payload.updates.find((u) => u.key === 'flag1');
expect(flag1Update).toBeDefined();
expect(flag1Update!.kind).toBe('flagEval');
expect(flag1Update!.kind).toBe('flag-eval');
expect(flag1Update!.version).toBe(1);

const flag2Update = result.payload.updates.find((u) => u.key === 'flag2');
expect(flag2Update).toBeDefined();
expect(flag2Update!.kind).toBe('flagEval');
expect(flag2Update!.kind).toBe('flag-eval');
expect(flag2Update!.version).toBe(2);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ describe('given a partial (changes) transfer', () => {
{
event: 'put-object',
data: {
kind: 'flagEval',
kind: 'flag-eval',
key: 'updatedFlag',
version: 5,
object: { value: 'new-value', trackEvents: true },
Expand Down Expand Up @@ -499,7 +499,7 @@ describe('given a delete-object event', () => {
{
event: 'delete-object',
data: {
kind: 'flagEval',
kind: 'flag-eval',
key: 'deletedFlag',
version: 3,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ it('produces a partial changeSet for incremental updates', async () => {
await base.takeResult();

simulateEvent(mockEventSource, 'put-object', {
kind: 'flagEval',
kind: 'flag-eval',
key: 'flag-a',
version: 2,
object: { value: false, trackEvents: true },
});
simulateEvent(mockEventSource, 'delete-object', {
kind: 'flagEval',
kind: 'flag-eval',
key: 'flag-b',
version: 3,
});
Expand Down Expand Up @@ -165,7 +165,7 @@ it('silently ignores unrecognized object kinds', async () => {
payloads: [{ intentCode: 'xfer-full', id: 'p1', target: 1, reason: 'test' }],
});
simulateEvent(mockEventSource, 'put-object', {
kind: 'flagEval',
kind: 'flag-eval',
key: 'known',
version: 1,
object: { value: true, trackEvents: false },
Expand Down Expand Up @@ -291,7 +291,7 @@ it('resets protocol handler on reconnection (onopen)', async () => {
payloads: [{ intentCode: 'xfer-full', id: 'p1', target: 1, reason: 'test' }],
});
simulateEvent(mockEventSource, 'put-object', {
kind: 'flagEval',
kind: 'flag-eval',
key: 'flag-a',
version: 1,
object: { value: true, trackEvents: false },
Expand Down Expand Up @@ -322,7 +322,9 @@ it('handles ping events by calling ping handler and queuing the result', async (
version: 1,
state: '(p:p1:1)',
type: 'full' as const,
updates: [{ kind: 'flagEval', key: 'ping-flag', version: 1, object: { value: 'from-ping' } }],
updates: [
{ kind: 'flag-eval', key: 'ping-flag', version: 1, object: { value: 'from-ping' } },
],
},
fdv1Fallback: false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ it('returns successive changeSet results', async () => {

const p2 = synchronizer.next();
simulateEvent(mockEventSource, 'put-object', {
kind: 'flagEval',
kind: 'flag-eval',
key: 'flag-2',
version: 2,
object: { value: 'second', trackEvents: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function sendFullTransfer(

flags.forEach((flag) => {
simulateEvent(mockEventSource, 'put-object', {
kind: 'flagEval',
kind: 'flag-eval',
key: flag.key,
version: flag.version,
object: { value: flag.value, trackEvents: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function makeFullPayloadBody(
events.push({
event: 'put-object',
data: {
kind: 'flagEval',
kind: 'flag-eval',
key,
version: 1,
object: { value: flag.value, trackEvents: flag.trackEvents ?? false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ it('passes through objects with extra unrecognized fields in processFlagEval', (

it('converts a put update with all fields into an ItemDescriptor', () => {
const update: internal.Update = {
kind: 'flagEval',
kind: 'flag-eval',
key: 'my-flag',
version: 5,
object: fullEvalResult,
Expand All @@ -66,7 +66,7 @@ it('converts a put update with all fields into an ItemDescriptor', () => {

it('preserves all FlagEvaluationResult fields on the mapped flag', () => {
const update: internal.Update = {
kind: 'flagEval',
kind: 'flag-eval',
key: 'all-fields',
version: 5,
object: fullEvalResult,
Expand All @@ -84,7 +84,7 @@ it('preserves all FlagEvaluationResult fields on the mapped flag', () => {

it('converts a put update with only required fields', () => {
const update: internal.Update = {
kind: 'flagEval',
kind: 'flag-eval',
key: 'minimal-flag',
version: 1,
object: minimalEvalResult,
Expand All @@ -106,7 +106,7 @@ it('converts a put update with only required fields', () => {

it('converts a delete update into a tombstone descriptor', () => {
const update: internal.Update = {
kind: 'flagEval',
kind: 'flag-eval',
key: 'deleted-flag',
version: 10,
deleted: true,
Expand All @@ -123,7 +123,7 @@ it('converts a delete update into a tombstone descriptor', () => {

it('uses the envelope version as both ItemDescriptor.version and Flag.version', () => {
const update: internal.Update = {
kind: 'flagEval',
kind: 'flag-eval',
key: 'versioned-flag',
version: 99,
object: { ...minimalEvalResult, flagVersion: 7 },
Expand All @@ -138,7 +138,7 @@ it('uses the envelope version as both ItemDescriptor.version and Flag.version',

it('handles null value in evaluation result', () => {
const update: internal.Update = {
kind: 'flagEval',
kind: 'flag-eval',
key: 'null-flag',
version: 1,
object: { value: null, trackEvents: false },
Expand All @@ -152,7 +152,7 @@ it('handles null value in evaluation result', () => {
it('handles complex object values', () => {
const complexValue = { nested: { deeply: { value: [1, 2, 3] } } };
const update: internal.Update = {
kind: 'flagEval',
kind: 'flag-eval',
key: 'complex-flag',
version: 3,
object: { value: complexValue, trackEvents: true },
Expand All @@ -166,13 +166,13 @@ it('handles complex object values', () => {
it('converts multiple flagEval updates into a map of ItemDescriptors', () => {
const updates: internal.Update[] = [
{
kind: 'flagEval',
kind: 'flag-eval',
key: 'flag-1',
version: 1,
object: { value: true, trackEvents: false },
},
{
kind: 'flagEval',
kind: 'flag-eval',
key: 'flag-2',
version: 2,
object: { value: 'blue', trackEvents: true, variation: 0 },
Expand All @@ -190,7 +190,7 @@ it('converts multiple flagEval updates into a map of ItemDescriptors', () => {
it('silently ignores updates with unrecognized kinds', () => {
const updates: internal.Update[] = [
{
kind: 'flagEval',
kind: 'flag-eval',
key: 'known-flag',
version: 1,
object: { value: true, trackEvents: false },
Expand Down Expand Up @@ -225,13 +225,13 @@ it('returns an empty map for an empty updates array', () => {
it('handles a mix of puts and deletes', () => {
const updates: internal.Update[] = [
{
kind: 'flagEval',
kind: 'flag-eval',
key: 'active-flag',
version: 5,
object: { value: 'red', trackEvents: true },
},
{
kind: 'flagEval',
kind: 'flag-eval',
key: 'removed-flag',
version: 3,
deleted: true,
Expand All @@ -250,13 +250,13 @@ it('handles a mix of puts and deletes', () => {
it('uses the last update when a key appears multiple times', () => {
const updates: internal.Update[] = [
{
kind: 'flagEval',
kind: 'flag-eval',
key: 'dup-flag',
version: 1,
object: { value: 'first', trackEvents: false },
},
{
kind: 'flagEval',
kind: 'flag-eval',
key: 'dup-flag',
version: 2,
object: { value: 'second', trackEvents: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ function transferredEvent(state: string, version: number): internal.FDv2Event {
}

function createHandler() {
return internal.createProtocolHandler({ flagEval: processFlagEval });
return internal.createProtocolHandler({ 'flag-eval': processFlagEval });
}

it('processes flagEval put-object events through the protocol handler', () => {
const handler = createHandler();
handler.processEvent(intentEvent('xfer-full', 'p1', 1));
handler.processEvent(
putEvent('flagEval', 'my-flag', 5, {
putEvent('flag-eval', 'my-flag', 5, {
flagVersion: 42,
value: 'green',
variation: 1,
Expand All @@ -47,7 +47,7 @@ it('processes flagEval put-object events through the protocol handler', () => {
if (action.type !== 'payload') return;

expect(action.payload.updates).toHaveLength(1);
expect(action.payload.updates[0].kind).toBe('flagEval');
expect(action.payload.updates[0].kind).toBe('flag-eval');
expect(action.payload.updates[0].key).toBe('my-flag');
expect(action.payload.updates[0].version).toBe(5);
expect(action.payload.updates[0].object.value).toBe('green');
Expand All @@ -56,14 +56,14 @@ it('processes flagEval put-object events through the protocol handler', () => {
it('processes flagEval delete-object events through the protocol handler', () => {
const handler = createHandler();
handler.processEvent(intentEvent('xfer-changes', 'p1', 1));
handler.processEvent(deleteEvent('flagEval', 'old-flag', 10));
handler.processEvent(deleteEvent('flag-eval', 'old-flag', 10));

const action = handler.processEvent(transferredEvent('(p:p1:1)', 1));
expect(action.type).toBe('payload');
if (action.type !== 'payload') return;

expect(action.payload.updates).toHaveLength(1);
expect(action.payload.updates[0].kind).toBe('flagEval');
expect(action.payload.updates[0].kind).toBe('flag-eval');
expect(action.payload.updates[0].key).toBe('old-flag');
expect(action.payload.updates[0].version).toBe(10);
expect(action.payload.updates[0].deleted).toBe(true);
Expand All @@ -72,7 +72,7 @@ it('processes flagEval delete-object events through the protocol handler', () =>
it('silently ignores unrecognized object kinds when flagEval is the only processor', () => {
const handler = createHandler();
handler.processEvent(intentEvent('xfer-full', 'p1', 1));
handler.processEvent(putEvent('flagEval', 'known', 1, { value: true, trackEvents: false }));
handler.processEvent(putEvent('flag-eval', 'known', 1, { value: true, trackEvents: false }));
handler.processEvent(putEvent('unknown_kind', 'mystery', 1, { data: 'ignored' }));

const action = handler.processEvent(transferredEvent('(p:p1:1)', 1));
Expand All @@ -86,11 +86,11 @@ it('silently ignores unrecognized object kinds when flagEval is the only process
it('handles a full transfer of multiple flagEval objects', () => {
const handler = createHandler();
handler.processEvent(intentEvent('xfer-full', 'p1', 52));
handler.processEvent(putEvent('flagEval', 'flag-a', 1, { value: true, trackEvents: false }));
handler.processEvent(putEvent('flag-eval', 'flag-a', 1, { value: true, trackEvents: false }));
handler.processEvent(
putEvent('flagEval', 'flag-b', 2, { value: 'blue', trackEvents: true, variation: 1 }),
putEvent('flag-eval', 'flag-b', 2, { value: 'blue', trackEvents: true, variation: 1 }),
);
handler.processEvent(putEvent('flagEval', 'flag-c', 3, { value: 42, trackEvents: false }));
handler.processEvent(putEvent('flag-eval', 'flag-c', 3, { value: 42, trackEvents: false }));

const action = handler.processEvent(transferredEvent('(p:p1:52)', 52));
expect(action.type).toBe('payload');
Expand All @@ -106,12 +106,12 @@ it('handles incremental updates with flagEval after a full transfer', () => {

// Full transfer
handler.processEvent(intentEvent('xfer-full', 'p1', 1));
handler.processEvent(putEvent('flagEval', 'flag-a', 1, { value: true, trackEvents: false }));
handler.processEvent(putEvent('flag-eval', 'flag-a', 1, { value: true, trackEvents: false }));
handler.processEvent(transferredEvent('(p:p1:1)', 1));

// Incremental update
handler.processEvent(putEvent('flagEval', 'flag-a', 2, { value: false, trackEvents: true }));
handler.processEvent(deleteEvent('flagEval', 'flag-b', 3));
handler.processEvent(putEvent('flag-eval', 'flag-a', 2, { value: false, trackEvents: true }));
handler.processEvent(deleteEvent('flag-eval', 'flag-b', 3));

const action = handler.processEvent(transferredEvent('(p:p1:2)', 2));
expect(action.type).toBe('payload');
Expand All @@ -120,12 +120,12 @@ it('handles incremental updates with flagEval after a full transfer', () => {
expect(action.payload.type).toBe('partial');
expect(action.payload.updates).toHaveLength(2);
expect(action.payload.updates[0]).toMatchObject({
kind: 'flagEval',
kind: 'flag-eval',
key: 'flag-a',
object: { value: false },
});
expect(action.payload.updates[1]).toMatchObject({
kind: 'flagEval',
kind: 'flag-eval',
key: 'flag-b',
deleted: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function loadFromCache(config: CacheInitializerConfig): Promise<FDv2Source

const updates: internal.Update[] = Object.entries(cached.flags).map(
([key, flag]): internal.Update => ({
kind: 'flagEval',
kind: 'flag-eval',
key,
version: flag.version,
object: flagToEvaluationResult(flag),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function processEvents(
): FDv2SourceResult {
const handler = internal.createProtocolHandler(
{
flagEval: processFlagEval,
'flag-eval': processFlagEval,
},
logger,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function createStreamingBase(config: {
}): StreamingFDv2Base {
const resultQueue = createAsyncQueue<FDv2SourceResult>();
const protocolHandler = internal.createProtocolHandler(
{ flagEval: processFlagEval },
{ 'flag-eval': processFlagEval },
config.logger,
);

Expand Down
8 changes: 4 additions & 4 deletions packages/shared/sdk-client/src/datasource/flagEvalMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ItemDescriptor } from '../flag-manager/ItemDescriptor';
import { FlagEvaluationResult } from '../types';

/**
* ObjProcessor for the `flagEval` object kind. Used by the protocol handler to
* ObjProcessor for the `flag-eval` object kind. Used by the protocol handler to
* process objects received in `put-object` events.
*
* Client-side evaluation results are already in their final form (pre-evaluated
Expand All @@ -15,7 +15,7 @@ export function processFlagEval(object: unknown): FlagEvaluationResult {
}

/**
* Converts an FDv2 {@link internal.Update} with `kind: 'flagEval'` into an
* Converts an FDv2 {@link internal.Update} with `kind: 'flag-eval'` into an
* {@link ItemDescriptor} suitable for {@link FlagManager}.
*
* For put updates the envelope `version` is used as the {@link ItemDescriptor.version}
Expand Down Expand Up @@ -49,7 +49,7 @@ export function flagEvalUpdateToItemDescriptor(update: internal.Update): ItemDes

/**
* Converts an array of FDv2 payload updates into a map of flag key to
* {@link ItemDescriptor}. Only `flagEval` kind updates are processed;
* {@link ItemDescriptor}. Only `flag-eval` kind updates are processed;
* unrecognized kinds are silently ignored.
*/
export function flagEvalPayloadToItemDescriptors(updates: internal.Update[]): {
Expand All @@ -58,7 +58,7 @@ export function flagEvalPayloadToItemDescriptors(updates: internal.Update[]): {
const descriptors: { [key: string]: ItemDescriptor } = {};

updates.forEach((update) => {
if (update.kind === 'flagEval') {
if (update.kind === 'flag-eval') {
descriptors[update.key] = flagEvalUpdateToItemDescriptor(update);
}
});
Expand Down
Loading