Skip to content

Commit 5d306fc

Browse files
docs: enhance typings and FlagStore documentation
Added experimental annotations to LDPlugin and LDDebugOverride interfaces in typings.d.ts. Add JSDoc comments to all FlagStore functions
1 parent 40a34b9 commit 5d306fc

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/FlagStore.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
const utils = require('./utils');
22

3+
/**
4+
* FlagStore - Centralized flag store and access point for all feature flags
5+
*
6+
* This module manages two types of feature flags:
7+
* 1. Regular flags - Retrieved from LaunchDarkly servers or bootstrap data
8+
* 2. Override flags - Local overrides for debugging/testing
9+
*
10+
* When a flag is requested:
11+
* - If an override exists for that flag, the override value is returned
12+
* - Otherwise, the regular flag value is returned
13+
*/
314
function FlagStore() {
415
let flags = {};
16+
// The flag overrides are set lazily to allow bypassing property checks when no overrides are present.
517
let flagOverrides;
618

19+
/**
20+
* Gets a single flag by key, with overrides taking precedence over regular flags
21+
* @param {string} key The flag key to retrieve
22+
* @returns {Object|null} The flag object or null if not found
23+
*/
724
function get(key) {
825
// Check overrides first, then real flags
926
if (flagOverrides && utils.objectHasOwnProperty(flagOverrides, key) && flagOverrides[key]) {
@@ -17,6 +34,10 @@ function FlagStore() {
1734
return null;
1835
}
1936

37+
/**
38+
* Gets all flags with overrides applied
39+
* @returns {Object} Object containing all flags with any overrides applied
40+
*/
2041
function getFlagsWithOverrides() {
2142
const result = {};
2243

@@ -41,17 +62,30 @@ function FlagStore() {
4162
return result;
4263
}
4364

65+
/**
66+
* Replaces all flags with new flag data
67+
* @param {Object} newFlags - Object containing the new flag data
68+
*/
4469
function setFlags(newFlags) {
4570
flags = { ...newFlags };
4671
}
4772

73+
/**
74+
* Sets an override value for a specific flag
75+
* @param {string} key The flag key to override
76+
* @param {*} value The override value for the flag
77+
*/
4878
function setOverride(key, value) {
4979
if (!flagOverrides) {
5080
flagOverrides = {};
5181
}
5282
flagOverrides[key] = { value };
5383
}
5484

85+
/**
86+
* Removes an override for a specific flag
87+
* @param {string} key The flag key to remove the override for
88+
*/
5589
function removeOverride(key) {
5690
if (!flagOverrides || !flagOverrides[key]) {
5791
return; // No override to remove
@@ -65,6 +99,10 @@ function FlagStore() {
6599
}
66100
}
67101

102+
/**
103+
* Clears all flag overrides and returns the cleared overrides
104+
* @returns {Object} The overrides that were cleared, useful for tracking what was removed
105+
*/
68106
function clearAllOverrides() {
69107
if (!flagOverrides) {
70108
return {}; // No overrides to clear, return empty object for consistency
@@ -75,10 +113,18 @@ function FlagStore() {
75113
return clearedOverrides;
76114
}
77115

116+
/**
117+
* Gets the internal flag state without overrides applied
118+
* @returns {Object} The internal flag data structure
119+
*/
78120
function getFlags() {
79121
return flags;
80122
}
81123

124+
/**
125+
* Gets the flag overrides data
126+
* @returns {Object} The flag overrides object, or empty object if no overrides exist
127+
*/
82128
function getFlagOverrides() {
83129
return flagOverrides || {};
84130
}

typings.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ export interface LDPlugin {
368368
* This method allows plugins to receive a debug override interface for
369369
* temporarily overriding flag values during development and testing.
370370
*
371+
* @experimental This interface is experimental and intended for use by LaunchDarkly tools at this time.
372+
* The API may change in future versions.
373+
*
371374
* @param debugOverride The debug override interface instance
372375
*/
373376
registerDebug?(debugOverride: LDDebugOverride): void;
@@ -378,6 +381,9 @@ export interface LDPlugin {
378381
* This interface provides methods to temporarily override flag values that take
379382
* precedence over the actual flag values from LaunchDarkly. These overrides are
380383
* useful for testing, development, and debugging scenarios.
384+
*
385+
* @experimental This interface is experimental and intended for use by LaunchDarkly tools at this time.
386+
* The API may change in future versions.
381387
*/
382388
export interface LDDebugOverride {
383389
/**

0 commit comments

Comments
 (0)