mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-14 01:16:17 +02:00
This commit changes our linter/formatter to biome (https://biomejs.dev/) Causing our prehook to run almost instantly, and our "yarn lint" task to run in sub 100ms. Some trade-offs: * Biome isn't quite as well established as ESLint * Are we ready to install a different vscode plugin (the biome plugin) instead of the prettier plugin The configuration set for biome also has a set of recommended rules, this is turned on by default, in order to get to something that was mergeable I have turned off a couple the rules we seemed to violate the most, that we also explicitly told eslint to ignore.
76 lines
2.5 KiB
TypeScript
76 lines
2.5 KiB
TypeScript
import { SdkContextSchema } from 'lib/openapi/spec/sdk-context-schema';
|
|
import { InMemStorageProvider, FeatureEvaluator } from './feature-evaluator';
|
|
import { FeatureConfigurationClient } from 'lib/types/stores/feature-strategies-store';
|
|
import { Segment } from './feature-evaluator/strategy/strategy';
|
|
import { ISegment } from 'lib/types/model';
|
|
import { serializeDates } from '../../types/serialize-dates';
|
|
import { Operator } from './feature-evaluator/constraint';
|
|
import { FeatureInterface } from 'unleash-client/lib/feature';
|
|
import { PayloadType } from 'unleash-client';
|
|
|
|
type NonEmptyList<T> = [T, ...T[]];
|
|
|
|
export const mapFeaturesForClient = (
|
|
features: FeatureConfigurationClient[],
|
|
): FeatureInterface[] =>
|
|
features.map((feature) => ({
|
|
impressionData: false,
|
|
...feature,
|
|
variants: (feature.variants || []).map((variant) => ({
|
|
overrides: [],
|
|
...variant,
|
|
payload: variant.payload && {
|
|
...variant.payload,
|
|
type: variant.payload.type as PayloadType,
|
|
},
|
|
})),
|
|
project: feature.project,
|
|
strategies: feature.strategies.map((strategy) => ({
|
|
parameters: {},
|
|
...strategy,
|
|
variants: (strategy.variants || []).map((variant) => ({
|
|
...variant,
|
|
payload: variant.payload && {
|
|
...variant.payload,
|
|
type: variant.payload.type as PayloadType,
|
|
},
|
|
})),
|
|
constraints: strategy.constraints?.map((constraint) => ({
|
|
inverted: false,
|
|
values: [],
|
|
...constraint,
|
|
operator: constraint.operator as unknown as Operator,
|
|
})),
|
|
})),
|
|
}));
|
|
|
|
export const mapSegmentsForClient = (segments: ISegment[]): Segment[] =>
|
|
serializeDates(segments) as Segment[];
|
|
|
|
export type ClientInitOptions = {
|
|
features: NonEmptyList<FeatureConfigurationClient>;
|
|
segments?: ISegment[];
|
|
context: SdkContextSchema;
|
|
logError: (message: any, ...args: any[]) => void;
|
|
};
|
|
|
|
export const offlineUnleashClient = async ({
|
|
features,
|
|
context,
|
|
segments,
|
|
}: ClientInitOptions): Promise<FeatureEvaluator> => {
|
|
const client = new FeatureEvaluator({
|
|
...context,
|
|
appName: context.appName,
|
|
storageProvider: new InMemStorageProvider(),
|
|
bootstrap: {
|
|
data: mapFeaturesForClient(features),
|
|
segments: mapSegmentsForClient(segments),
|
|
},
|
|
});
|
|
|
|
await client.start();
|
|
|
|
return client;
|
|
};
|