@featurevisor/sdk 0.36.0 → 0.37.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.
@@ -109,7 +109,7 @@ export function getBucketedNumber(bucketKey: string): number {
109
109
  <div class='footer quiet pad2 space-top1 center small'>
110
110
  Code coverage generated by
111
111
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
112
- at 2023-07-13T20:52:46.032Z
112
+ at 2023-07-14T17:03:15.956Z
113
113
  </div>
114
114
  <script src="prettify.js"></script>
115
115
  <script>
@@ -281,72 +281,72 @@
281
281
  <span class="cline-any cline-neutral">&nbsp;</span>
282
282
  <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import { compareVersions } from "compare-versions";
283
283
  &nbsp;
284
- import { Attributes, Condition, PlainCondition } from "@featurevisor/types";
284
+ import { Context, Condition, PlainCondition } from "@featurevisor/types";
285
285
  &nbsp;
286
- export function conditionIsMatched(condition: PlainCondition, attributes: Attributes): boolean {
286
+ export function conditionIsMatched(condition: PlainCondition, context: Context): boolean {
287
287
  const { attribute, operator, value } = condition;
288
288
  &nbsp;
289
289
  if (operator === "equals") {
290
- return attributes[attribute] === value;
290
+ return context[attribute] === value;
291
291
  } else if (operator === "notEquals") {
292
- return attributes[attribute] !== value;
292
+ return context[attribute] !== value;
293
293
  } else if (operator === "before" || operator === "after") {
294
294
  // date comparisons
295
- const valueInAttributes = attributes[attribute] as string | Date;
295
+ const valueInContext = context[attribute] as string | Date;
296
296
  &nbsp;
297
- const dateInAttributes =
298
- valueInAttributes instanceof Date ? valueInAttributes : new Date(valueInAttributes);
297
+ const dateInContext =
298
+ valueInContext instanceof Date ? valueInContext : new Date(valueInContext);
299
299
  const dateInCondition = value instanceof Date ? <span class="branch-0 cbranch-no" title="branch not covered" >value </span>: new Date(value as string);
300
300
  &nbsp;
301
301
  return operator === "before"
302
- ? dateInAttributes &lt; dateInCondition
303
- : dateInAttributes &gt; dateInCondition;
304
- } else <span class="missing-if-branch" title="if path not taken" >I</span>if (typeof attributes[attribute] === "string" &amp;&amp; Array.isArray(value)) {
302
+ ? dateInContext &lt; dateInCondition
303
+ : dateInContext &gt; dateInCondition;
304
+ } else <span class="missing-if-branch" title="if path not taken" >I</span>if (typeof context[attribute] === "string" &amp;&amp; Array.isArray(value)) {
305
305
  // array
306
- const valueInAttributes = <span class="cstat-no" title="statement not covered" >attributes[attribute] as string;</span>
306
+ const valueInContext = <span class="cstat-no" title="statement not covered" >context[attribute] as string;</span>
307
307
  &nbsp;
308
308
  <span class="cstat-no" title="statement not covered" > if (operator === "in") {</span>
309
- <span class="cstat-no" title="statement not covered" > return value.indexOf(valueInAttributes) !== -1;</span>
309
+ <span class="cstat-no" title="statement not covered" > return value.indexOf(valueInContext) !== -1;</span>
310
310
  } else <span class="cstat-no" title="statement not covered" ><span class="missing-if-branch" title="if path not taken" >I</span>if (operator === "notIn") {</span>
311
- <span class="cstat-no" title="statement not covered" > return value.indexOf(valueInAttributes) === -1;</span>
311
+ <span class="cstat-no" title="statement not covered" > return value.indexOf(valueInContext) === -1;</span>
312
312
  }
313
- } else if (typeof attributes[attribute] === "string" &amp;&amp; typeof value === "string") {
313
+ } else if (typeof context[attribute] === "string" &amp;&amp; typeof value === "string") {
314
314
  // string
315
- const valueInAttributes = attributes[attribute] as string;
315
+ const valueInContext = context[attribute] as string;
316
316
  &nbsp;
317
317
  <span class="missing-if-branch" title="if path not taken" >I</span>if (operator === "contains") {
318
- <span class="cstat-no" title="statement not covered" > return valueInAttributes.indexOf(value) !== -1;</span>
318
+ <span class="cstat-no" title="statement not covered" > return valueInContext.indexOf(value) !== -1;</span>
319
319
  } else <span class="missing-if-branch" title="if path not taken" >I</span>if (operator === "notContains") {
320
- <span class="cstat-no" title="statement not covered" > return valueInAttributes.indexOf(value) === -1;</span>
320
+ <span class="cstat-no" title="statement not covered" > return valueInContext.indexOf(value) === -1;</span>
321
321
  } else <span class="missing-if-branch" title="if path not taken" >I</span>if (operator === "startsWith") {
322
- <span class="cstat-no" title="statement not covered" > return valueInAttributes.startsWith(value);</span>
322
+ <span class="cstat-no" title="statement not covered" > return valueInContext.startsWith(value);</span>
323
323
  } else <span class="missing-if-branch" title="if path not taken" >I</span>if (operator === "endsWith") {
324
- <span class="cstat-no" title="statement not covered" > return valueInAttributes.endsWith(value);</span>
324
+ <span class="cstat-no" title="statement not covered" > return valueInContext.endsWith(value);</span>
325
325
  } else if (operator === "semverEquals") {
326
- return compareVersions(valueInAttributes, value) === 0;
326
+ return compareVersions(valueInContext, value) === 0;
327
327
  } else if (operator === "semverNotEquals") {
328
- return compareVersions(valueInAttributes, value) !== 0;
328
+ return compareVersions(valueInContext, value) !== 0;
329
329
  } else if (operator === "semverGreaterThan") {
330
- return compareVersions(valueInAttributes, value) === 1;
330
+ return compareVersions(valueInContext, value) === 1;
331
331
  } else if (operator === "semverGreaterThanOrEquals") {
332
- return compareVersions(valueInAttributes, value) &gt;= 0;
332
+ return compareVersions(valueInContext, value) &gt;= 0;
333
333
  } else if (operator === "semverLessThan") {
334
- return compareVersions(valueInAttributes, value) === -1;
334
+ return compareVersions(valueInContext, value) === -1;
335
335
  } else if (operator === "semverLessThanOrEquals") {
336
- return compareVersions(valueInAttributes, value) &lt;= 0;
336
+ return compareVersions(valueInContext, value) &lt;= 0;
337
337
  }
338
- } else if (typeof attributes[attribute] === "number" &amp;&amp; typeof value === "number") {
338
+ } else if (typeof context[attribute] === "number" &amp;&amp; typeof value === "number") {
339
339
  // numeric
340
- const valueInAttributes = attributes[attribute] as number;
340
+ const valueInContext = context[attribute] as number;
341
341
  &nbsp;
342
342
  if (operator === "greaterThan") {
343
- return valueInAttributes &gt; value;
343
+ return valueInContext &gt; value;
344
344
  } else <span class="missing-if-branch" title="if path not taken" >I</span>if (operator === "greaterThanOrEquals") {
345
- <span class="cstat-no" title="statement not covered" > return valueInAttributes &gt;= value;</span>
345
+ <span class="cstat-no" title="statement not covered" > return valueInContext &gt;= value;</span>
346
346
  } else if (operator === "lessThan") {
347
- return valueInAttributes &lt; value;
347
+ return valueInContext &lt; value;
348
348
  } else <span class="cstat-no" title="statement not covered" ><span class="missing-if-branch" title="if path not taken" >I</span><span class="missing-if-branch" title="else path not taken" >E</span>if (operator === "lessThanOrEquals") {</span>
349
- <span class="cstat-no" title="statement not covered" > return valueInAttributes &lt;= value;</span>
349
+ <span class="cstat-no" title="statement not covered" > return valueInContext &lt;= value;</span>
350
350
  }
351
351
  }
352
352
  &nbsp;
@@ -355,18 +355,18 @@ export function conditionIsMatched(condition: PlainCondition, attributes: Attrib
355
355
  &nbsp;
356
356
  export function allConditionsAreMatched(
357
357
  conditions: Condition[] | Condition,
358
- attributes: Attributes,
358
+ context: Context,
359
359
  ): boolean {
360
360
  if ("attribute" in conditions) {
361
- return conditionIsMatched(conditions, attributes);
361
+ return conditionIsMatched(conditions, context);
362
362
  }
363
363
  &nbsp;
364
364
  if ("and" in conditions &amp;&amp; Array.isArray(conditions.and)) {
365
- return conditions.and.every((c) =&gt; allConditionsAreMatched(c, attributes));
365
+ return conditions.and.every((c) =&gt; allConditionsAreMatched(c, context));
366
366
  }
367
367
  &nbsp;
368
368
  if ("or" in conditions &amp;&amp; Array.isArray(conditions.or)) {
369
- return conditions.or.some((c) =&gt; allConditionsAreMatched(c, attributes));
369
+ return conditions.or.some((c) =&gt; allConditionsAreMatched(c, context));
370
370
  }
371
371
  &nbsp;
372
372
  if ("not" in conditions &amp;&amp; Array.isArray(conditions.not)) {
@@ -376,13 +376,13 @@ export function allConditionsAreMatched(
376
376
  {
377
377
  and: conditions.not,
378
378
  },
379
- attributes,
379
+ context,
380
380
  ) === false,
381
381
  );
382
382
  }
383
383
  &nbsp;
384
384
  if (Array.isArray(conditions)) {
385
- return conditions.every((c) =&gt; allConditionsAreMatched(c, attributes));
385
+ return conditions.every((c) =&gt; allConditionsAreMatched(c, context));
386
386
  }
387
387
  &nbsp;
388
388
  <span class="cstat-no" title="statement not covered" > return false;</span>
@@ -394,7 +394,7 @@ export function allConditionsAreMatched(
394
394
  <div class='footer quiet pad2 space-top1 center small'>
395
395
  Code coverage generated by
396
396
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
397
- at 2023-07-13T20:52:46.032Z
397
+ at 2023-07-14T17:03:15.956Z
398
398
  </div>
399
399
  <script src="prettify.js"></script>
400
400
  <script>
@@ -289,7 +289,7 @@ export class DatafileReader {
289
289
  <div class='footer quiet pad2 space-top1 center small'>
290
290
  Code coverage generated by
291
291
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
292
- at 2023-07-13T20:52:46.032Z
292
+ at 2023-07-14T17:03:15.956Z
293
293
  </div>
294
294
  <script src="prettify.js"></script>
295
295
  <script>
@@ -229,7 +229,7 @@ export class Emitter {
229
229
  <div class='footer quiet pad2 space-top1 center small'>
230
230
  Code coverage generated by
231
231
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
232
- at 2023-07-13T20:52:46.032Z
232
+ at 2023-07-14T17:03:15.956Z
233
233
  </div>
234
234
  <script src="prettify.js"></script>
235
235
  <script>
@@ -227,7 +227,7 @@
227
227
  <span class="cline-any cline-no">&nbsp;</span>
228
228
  <span class="cline-any cline-neutral">&nbsp;</span>
229
229
  <span class="cline-any cline-neutral">&nbsp;</span>
230
- <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import { Allocation, Attributes, Traffic, Feature, Force } from "@featurevisor/types";
230
+ <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import { Allocation, Context, Traffic, Feature, Force } from "@featurevisor/types";
231
231
  import { DatafileReader } from "./datafileReader";
232
232
  import { allGroupSegmentsAreMatched } from "./segments";
233
233
  import { allConditionsAreMatched } from "./conditions";
@@ -255,7 +255,7 @@ export interface MatchedTrafficAndAllocation {
255
255
  &nbsp;
256
256
  export function getMatchedTrafficAndAllocation(
257
257
  traffic: Traffic[],
258
- attributes: Attributes,
258
+ context: Context,
259
259
  bucketValue: number,
260
260
  datafileReader: DatafileReader,
261
261
  logger: Logger,
@@ -266,7 +266,7 @@ export function getMatchedTrafficAndAllocation(
266
266
  <span class="missing-if-branch" title="if path not taken" >I</span>if (
267
267
  !allGroupSegmentsAreMatched(
268
268
  typeof t.segments === "string" &amp;&amp; t.segments !== "*" ? <span class="branch-0 cbranch-no" title="branch not covered" >JSON.parse(t.segments) </span>: t.segments,
269
- attributes,
269
+ context,
270
270
  datafileReader,
271
271
  )
272
272
  ) {
@@ -290,7 +290,7 @@ export function getMatchedTrafficAndAllocation(
290
290
  &nbsp;
291
291
  export function findForceFromFeature(
292
292
  feature: Feature,
293
- attributes: Attributes,
293
+ context: Context,
294
294
  datafileReader: DatafileReader,
295
295
  ): Force | undefined {
296
296
  if (!feature.force) {
@@ -299,11 +299,11 @@ export function findForceFromFeature(
299
299
  &nbsp;
300
300
  <span class="cstat-no" title="statement not covered" > return feature.force.find(<span class="fstat-no" title="function not covered" >(f</span>: Force) =&gt; {</span>
301
301
  <span class="cstat-no" title="statement not covered" > <span class="missing-if-branch" title="if path not taken" >I</span>if (f.conditions) {</span>
302
- <span class="cstat-no" title="statement not covered" > return allConditionsAreMatched(f.conditions, attributes);</span>
302
+ <span class="cstat-no" title="statement not covered" > return allConditionsAreMatched(f.conditions, context);</span>
303
303
  }
304
304
  &nbsp;
305
305
  <span class="cstat-no" title="statement not covered" > <span class="missing-if-branch" title="if path not taken" >I</span>if (f.segments) {</span>
306
- <span class="cstat-no" title="statement not covered" > return allGroupSegmentsAreMatched(f.segments, attributes, datafileReader);</span>
306
+ <span class="cstat-no" title="statement not covered" > return allGroupSegmentsAreMatched(f.segments, context, datafileReader);</span>
307
307
  }
308
308
  &nbsp;
309
309
  <span class="cstat-no" title="statement not covered" > return false;</span>
@@ -316,7 +316,7 @@ export function findForceFromFeature(
316
316
  <div class='footer quiet pad2 space-top1 center small'>
317
317
  Code coverage generated by
318
318
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
319
- at 2023-07-13T20:52:46.032Z
319
+ at 2023-07-14T17:03:15.956Z
320
320
  </div>
321
321
  <script src="prettify.js"></script>
322
322
  <script>
@@ -206,7 +206,7 @@
206
206
  <div class='footer quiet pad2 space-top1 center small'>
207
207
  Code coverage generated by
208
208
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
209
- at 2023-07-13T20:52:46.032Z
209
+ at 2023-07-14T17:03:15.956Z
210
210
  </div>
211
211
  <script src="prettify.js"></script>
212
212
  <script>