Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rollup.config.jsの拡張子を.mjsに変更 #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pkgs.stdenv.mkDerivation rec {

buildPhase=''
HOME=$TMP yarn install --frozen-lockfile
yarn rollup --config ./rollup.config.js
yarn rollup --config ./rollup.config.mjs
cp ./package.json ./README.md ./dist
cd ./dist
yarn pack
Expand Down
47 changes: 47 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { Driver } from '@cycle/run';
import type { Decoder } from 'io-ts/Decoder';
import * as LaunchDarkly from 'launchdarkly-js-client-sdk';
import { type MemoryStream, Stream } from 'xstream';
declare type Dictionary = Readonly<{
[_: string]: unknown;
}>;
export interface FeaturesSource<Features extends Dictionary> {
readonly stream: MemoryStream<Features>;
}
declare type LDParams = Parameters<typeof LaunchDarkly.initialize>;
export declare type Params<Features extends Dictionary> = Readonly<{
/**
* The decoder for the feature flags.
*/
decoder: Decoder<unknown, Features>;
/**
* The default values of the feature flags.
*/
defaultValues: Features;
/**
* The client-side ID.
*/
envKey: LDParams[0];
/**
* When the LaunchDarkly client initialization exceeds this duration, the default values will be emitted to the sink.
* In milliseconds.
*/
fallbackDelay?: number | undefined;
/**
* Optional configuration settings.
*/
options?: LDParams[2];
/**
* The initial user properties.
*/
user: LDParams[1];
}>;
/**
* A factory function for the LaunchDarkly driver.
*/
export declare function makeLaunchDarklyDriver<Features extends Dictionary>({ decoder, defaultValues, envKey, fallbackDelay, options, user, }: Params<Features>): Driver<void, FeaturesSource<Features>>;
/**
* A factory function to create a mocked `FeaturesSource`, for testing purposes.
*/
export declare function makeMockFeaturesDriver<Features extends Dictionary>($: Stream<Features>): Driver<void, FeaturesSource<Features>>;
export {};
68 changes: 68 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as E from 'fp-ts/Either';
import { pipe } from 'fp-ts/function';
import * as LaunchDarkly from 'launchdarkly-js-client-sdk';
import { Stream } from 'xstream';
import delay from 'xstream/extra/delay';

function makeClient$(...[envKey, user, options]) {
let client;
return Stream.create({
start: (listener) => {
client = LaunchDarkly.initialize(envKey, user, options);
void client.waitForInitialization().then(() => {
if (client === undefined) {
return;
}
listener.next(client);
});
},
stop: () => {
void client?.close();
client = undefined;
},
});
}
/**
* A factory function for the LaunchDarkly driver.
*/
function makeLaunchDarklyDriver({ decoder, defaultValues, envKey, fallbackDelay = 0, options, user, }) {
const client$ = makeClient$(envKey, user, options);
const $ = client$.map((client) => {
let onNext;
let onError;
return Stream.create({
start(listener) {
onNext = () => {
const allFlags = client.allFlags();
const flags = decoder.decode(allFlags);
const action = pipe(flags, E.fold(() => () => options?.logger?.warn(`Failed to decode the flags: ${JSON.stringify(allFlags)}`), (flags) => () => {
listener.next(flags);
}));
action();
};
onError = listener.error;
client.on('change', onNext);
client.on('error', listener.error);
client.on('failed', listener.error);
onNext();
},
stop() {
client.off('change', onNext);
client.off('error', onError);
client.on('failed', onError);
},
});
});
const defaultValues$ = Stream.of(defaultValues).compose(delay(fallbackDelay));
return () => ({
stream: $.startWith(defaultValues$).flatten(),
});
}
/**
* A factory function to create a mocked `FeaturesSource`, for testing purposes.
*/
function makeMockFeaturesDriver($) {
return () => ({ stream: $ });
}

export { makeLaunchDarklyDriver, makeMockFeaturesDriver };
File renamed without changes.