-
Notifications
You must be signed in to change notification settings - Fork 30
fix: Suggestions for serialization. #111
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,11 @@ const createFeatureStore = (kvNamespace: KVNamespace, sdkKey: string, logger: LD | |
const store: LDFeatureStore = { | ||
get( | ||
kind: DataKind, | ||
flagKey: string, | ||
dataKey: string, | ||
callback: (res: LDFeatureStoreItem | null) => void = noop | ||
): void { | ||
const kindKey = kind.namespace === 'features' ? 'flags' : kind.namespace; | ||
logger.debug(`Requesting ${flagKey} from ${key}.${kindKey}`); | ||
logger.debug(`Requesting ${dataKey} from ${key}.${kindKey}`); | ||
|
||
kvNamespace | ||
.get(key) | ||
|
@@ -32,7 +32,17 @@ const createFeatureStore = (kvNamespace: KVNamespace, sdkKey: string, logger: LD | |
if (!item) { | ||
throw new Error(`Error deserializing ${kindKey}`); | ||
} | ||
callback(item[kindKey][flagKey]); | ||
switch (kind.namespace) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't super elegant, but lets us keep the types the same, and we can make it more elegant in the next update. |
||
case 'features': | ||
callback(item.flags[dataKey]); | ||
break; | ||
case 'segments': | ||
callback(item.segments[dataKey]); | ||
break; | ||
default: | ||
// Unsupported data kind. | ||
callback(null); | ||
} | ||
}) | ||
.catch((err) => { | ||
logger.error(err); | ||
|
@@ -54,7 +64,17 @@ const createFeatureStore = (kvNamespace: KVNamespace, sdkKey: string, logger: LD | |
throw new Error(`Error deserializing ${kindKey}`); | ||
} | ||
|
||
callback(item[kindKey]); | ||
switch (kind.namespace) { | ||
case 'features': | ||
callback(item.flags); | ||
break; | ||
case 'segments': | ||
callback(item.segments); | ||
break; | ||
default: | ||
// Unsupported data kind. | ||
callback({}); | ||
} | ||
}) | ||
.catch((err) => { | ||
logger.error(err); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ export function reviver(this: any, key: string, value: any): any { | |
} | ||
|
||
interface FlagsAndSegments { | ||
[key: string]: { [name: string]: Flag } | { [name: string]: Segment }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FlagsAndSegments isn't intended to be addressed by strings. In places where it isn't flags or segments it would generally be an error. So, this is the main thing I was concerned about. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe long term export interface DataKind {
namespace: 'flags' | 'segments';
} |
||
flags: { [name: string]: Flag }; | ||
segments: { [name: string]: Segment }; | ||
} | ||
|
@@ -158,6 +157,14 @@ export function deserializeAll(data: string): AllData | undefined { | |
return parsed; | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just because this isn't a permanent solution, and isn't a function we want a customer to use. |
||
* This function is intended for usage inside LaunchDarkly SDKs. | ||
* This function should NOT be used by customer applications. | ||
* This function may be changed or removed without a major version. | ||
* | ||
* @param data String data from launchdarkly. | ||
* @returns The parsed and processed data. | ||
*/ | ||
export function deserializePoll(data: string): FlagsAndSegments | undefined { | ||
const parsed = tryParse(data) as FlagsAndSegments; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't just flags.