@flag-engine/core 0.0.4 → 0.0.6
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/__tests__/isEligibleForStrategy.test.d.ts +2 -0
- package/dist/__tests__/isEligibleForStrategy.test.d.ts.map +1 -0
- package/dist/getEligibleStrategy.d.ts +2 -1
- package/dist/getEligibleStrategy.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/types.d.ts +5 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isEligibleForStrategy.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/isEligibleForStrategy.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { FlagConfiguration, UserConfiguration } from "./types";
|
|
1
|
+
import { FlagConfiguration, Rule, UserConfiguration } from "./types";
|
|
2
|
+
export declare const isEligibleForStrategy: (rules: Rule[], userConfiguration: UserConfiguration) => boolean;
|
|
2
3
|
export declare const getEligibleStrategy: (flagConfig: FlagConfiguration, userConfiguration: UserConfiguration) => import("./types").Strategy | undefined;
|
|
3
4
|
//# sourceMappingURL=getEligibleStrategy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEligibleStrategy.d.ts","sourceRoot":"","sources":["../src/getEligibleStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"getEligibleStrategy.d.ts","sourceRoot":"","sources":["../src/getEligibleStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAOrE,eAAO,MAAM,qBAAqB,UACzB,IAAI,EAAE,qBACM,iBAAiB,KACnC,OAuEF,CAAC;AAEF,eAAO,MAAM,mBAAmB,eAClB,iBAAiB,qBACV,iBAAiB,2CAKrC,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("murmurhash-js");const t=e=>"
|
|
1
|
+
"use strict";var e=require("murmurhash-js");const t=e=>"string"==typeof e,r=e=>null==e,n=(e,a)=>0===e.length||e.every((e=>{if("inSegment"in e)return n(e.inSegment.rules,a);switch(e.operator){case"equals":return a[e.field]===e.value;case"not_equals":return a[e.field]!==e.value;case"greater_than":{const t=a[e.field];return!r(t)&&!r(e.value)&&t>e.value}case"less_than":{const t=a[e.field];return!r(t)&&!r(e.value)&&t<e.value}case"contains":{const r=a[e.field];return t(r)&&t(e.value)&&r.includes(e.value)}case"not_contains":{const r=a[e.field];return t(r)&&t(e.value)&&!r.includes(e.value)}case"in":{const t=a[e.field];return Array.isArray(e.value)&&-1!==e.value.indexOf(t)}case"not_in":{const t=a[e.field];return Array.isArray(e.value)&&-1===e.value.indexOf(t)}default:return!1}})),a=Math.pow(2,32),s=(t,r)=>{if(0===t.strategies.length)return!0;const s=((e,t)=>e.strategies.find((e=>n(e.rules,t))))(t,r);if(!s)return!1;if(0===s.variants.length)return!0;const u=((t,r)=>{t.variants.sort(((e,t)=>e.percent-t.percent));let n=0;const s=t.variants.find((t=>{const s=`${t.name}-${r}`,u=e.murmur3(s)/a*100;if(n+=t.percent,u<=n)return t}));return s||!1})(s,r.__id);return!!u&&u.name};exports.createFlagEngine=e=>({createUserContext:t=>((e,t)=>{let r=t;return{evaluateAll:()=>{const t={};for(const n of e)t[n.key]="enabled"===n.status&&s(n,r);return t},evaluate:t=>{const n=e.find((e=>e.key===t));return!!n&&"disabled"!==n.status&&s(n,r)},setUserConfiguration:e=>{r=e}}})(e,t)});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{murmur3 as e}from"murmurhash-js";const t=e=>"
|
|
1
|
+
import{murmur3 as e}from"murmurhash-js";const t=e=>"string"==typeof e,n=e=>null==e,r=(e,a)=>0===e.length||e.every((e=>{if("inSegment"in e)return r(e.inSegment.rules,a);switch(e.operator){case"equals":return a[e.field]===e.value;case"not_equals":return a[e.field]!==e.value;case"greater_than":{const t=a[e.field];return!n(t)&&!n(e.value)&&t>e.value}case"less_than":{const t=a[e.field];return!n(t)&&!n(e.value)&&t<e.value}case"contains":{const n=a[e.field];return t(n)&&t(e.value)&&n.includes(e.value)}case"not_contains":{const n=a[e.field];return t(n)&&t(e.value)&&!n.includes(e.value)}case"in":{const t=a[e.field];return Array.isArray(e.value)&&-1!==e.value.indexOf(t)}case"not_in":{const t=a[e.field];return Array.isArray(e.value)&&-1===e.value.indexOf(t)}default:return!1}})),a=Math.pow(2,32),s=(t,n)=>{if(0===t.strategies.length)return!0;const s=((e,t)=>e.strategies.find((e=>r(e.rules,t))))(t,n);if(!s)return!1;if(0===s.variants.length)return!0;const u=((t,n)=>{t.variants.sort(((e,t)=>e.percent-t.percent));let r=0;const s=t.variants.find((t=>{const s=`${t.name}-${n}`,u=e(s)/a*100;if(r+=t.percent,u<=r)return t}));return s||!1})(s,n.__id);return!!u&&u.name},u=e=>({createUserContext:t=>((e,t)=>{let n=t;return{evaluateAll:()=>{const t={};for(const r of e)t[r.key]="enabled"===r.status&&s(r,n);return t},evaluate:t=>{const r=e.find((e=>e.key===t));return!!r&&"disabled"!==r.status&&s(r,n)},setUserConfiguration:e=>{n=e}}})(e,t)});export{u as createFlagEngine};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type FlagStatus = "enabled" | "disabled";
|
|
2
|
-
export type ConditionOperator = "equals" | "not_equals" | "contains" | "not_contains" | "greater_than" | "less_than" | "in";
|
|
3
|
-
|
|
2
|
+
export type ConditionOperator = "equals" | "not_equals" | "contains" | "not_contains" | "greater_than" | "less_than" | "in" | "not_in";
|
|
3
|
+
type RuleValuePrimitive = object | null | undefined | string | number | boolean | Date;
|
|
4
|
+
export type RuleValue = RuleValuePrimitive | Array<RuleValuePrimitive>;
|
|
4
5
|
export type Rule = {
|
|
5
6
|
field: string;
|
|
6
7
|
operator: ConditionOperator;
|
|
@@ -28,7 +29,7 @@ export type FlagConfiguration = {
|
|
|
28
29
|
};
|
|
29
30
|
export type UserConfiguration = {
|
|
30
31
|
__id: string;
|
|
31
|
-
[key: string]:
|
|
32
|
+
[key: string]: RuleValuePrimitive;
|
|
32
33
|
};
|
|
33
34
|
export type FlagsConfiguration = Array<FlagConfiguration>;
|
|
34
35
|
export type FlagDict = Record<string, string | boolean>;
|
|
@@ -40,4 +41,5 @@ export interface UserContextFlagEvaluation {
|
|
|
40
41
|
export interface EvaluationMachine {
|
|
41
42
|
createUserContext: (userConfiguration: UserConfiguration) => UserContextFlagEvaluation;
|
|
42
43
|
}
|
|
44
|
+
export {};
|
|
43
45
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,UAAU,CAAC;AAChD,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,YAAY,GACZ,UAAU,GACV,cAAc,GACd,cAAc,GACd,WAAW,GACX,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,UAAU,CAAC;AAChD,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,YAAY,GACZ,UAAU,GACV,cAAc,GACd,cAAc,GACd,WAAW,GACX,IAAI,GACJ,QAAQ,CAAC;AAEb,KAAK,kBAAkB,GACnB,MAAM,GACN,IAAI,GACJ,SAAS,GACT,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,CAAC;AAET,MAAM,MAAM,SAAS,GAAG,kBAAkB,GAAG,KAAK,CAAC,kBAAk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AAM,WAAW,iBAAiB;IAChC,iBAAiB,EAAE,CACjB,iBAAiB,EAAE,iBAAiB,KACjC,yBAAyB,CAAC;CAChC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flag-engine/core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"description": "Feature flags evaluation engine, runtime agnostic",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"types": "./dist/index.d.ts",
|
|
17
17
|
"scripts": {
|
|
18
|
-
"build": "rollup -c rollup.config.mjs",
|
|
18
|
+
"build": "rm -rf dist .turbo && rollup -c rollup.config.mjs",
|
|
19
19
|
"start": "tsx src/index.ts",
|
|
20
20
|
"test": "vitest",
|
|
21
21
|
"coverage": "vitest run --coverage",
|