Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 1e0b214

Browse files
authored
fix import of SDK interfaces, + minor doc fix (#8)
1 parent 475b585 commit 1e0b214

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ To run all unit tests:
3232
npm test
3333
```
3434

35-
The tests expect you to have Redis running locally on the default port, 6379. One way to do this is with Docker: `docker run -d -p 6379:6379 redis`
35+
The tests expect you to have Redis running locally on the default port, 6379. One way to do this is with Docker:
36+
37+
```
38+
docker run -p 6379:6379 redis
39+
```
3640

3741
To verify that the TypeScript declarations compile correctly (this involves compiling the file `test-types.ts`, so if you have changed any types or interfaces, you will want to update that code):
3842

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
declare module 'launchdarkly-node-server-sdk-redis' {
1010
import { LDFeatureStore, LDLogger, LDOptions } from 'launchdarkly-node-server-sdk';
11-
import * as ld from 'launchdarkly-node-server-sdk';
11+
import { BigSegmentStore } from 'launchdarkly-node-server-sdk/interfaces';
1212
import { ClientOpts, RedisClient } from 'redis';
1313

1414
/**
@@ -77,7 +77,7 @@ declare module 'launchdarkly-node-server-sdk-redis' {
7777
*/
7878
export function RedisBigSegmentStore(
7979
options?: LDRedisOptions
80-
): (config: LDOptions) => ld.interfaces.BigSegmentStore;
80+
): (config: LDOptions) => BigSegmentStore;
8181

8282
/**
8383
* The standard options supported for the LaunchDarkly Redis integration.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"jest": "^27.0.4",
2323
"jest-junit": "^12.2.0",
2424
"launchdarkly-js-test-helpers": "^1.2.1",
25-
"launchdarkly-node-server-sdk": "6.2.0-alpha.bigsegments.3",
25+
"launchdarkly-node-server-sdk": "6.2.0-alpha.bigsegments.4",
2626
"prettier": "^2.3.1",
2727
"typescript": "^4.3.2"
2828
},

tests/redis_stores-test.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@ const {
77
const redis = require('redis');
88
const { promisify } = require('util');
99

10+
const defaultPrefix = 'launchdarkly';
11+
1012
// Runs the standard test suites provided by the SDK's store_tests module.
1113

1214
// This is a single file because if the two test suites were run from separate files, they could
1315
// be interleaved by Jest. Since our implementation of clearAllData is not very smart and will
1416
// remove *all* keys with the given prefix, we could step on another test's data if the shared
1517
// test suites happen to use the same prefix.
1618

19+
function actualPrefix(prefix) {
20+
return prefix || defaultPrefix;
21+
}
22+
1723
function clearAllData(client) {
1824
return async prefix => {
19-
const keys = await promisify(client.keys.bind(client))(prefix + ':*');
25+
const keys = await promisify(client.keys.bind(client))(actualPrefix(prefix) + ':*');
2026
for (const key of keys) {
2127
await promisify(client.del.bind(client))(key);
2228
}
@@ -59,16 +65,16 @@ describe('RedisBigSegmentStore', () => {
5965
}
6066

6167
async function setMetadata(prefix, metadata) {
62-
await promisify(client.set.bind(client))(prefix + ':' + keyLastUpToDate,
68+
await promisify(client.set.bind(client))(actualPrefix(prefix) + ':' + keyLastUpToDate,
6369
metadata.lastUpToDate ? metadata.lastUpToDate.toString() : '');
6470
}
6571

6672
async function setSegments(prefix, userHashKey, includes, excludes) {
6773
for (const ref of includes) {
68-
await promisify(client.sadd.bind(client))(prefix + ':' + keyUserInclude + userHashKey, ref);
74+
await promisify(client.sadd.bind(client))(actualPrefix(prefix) + ':' + keyUserInclude + userHashKey, ref);
6975
}
7076
for (const ref of excludes) {
71-
await promisify(client.sadd.bind(client))(prefix + ':' + keyUserExclude + userHashKey, ref);
77+
await promisify(client.sadd.bind(client))(actualPrefix(prefix) + ':' + keyUserExclude + userHashKey, ref);
7278
}
7379
}
7480

0 commit comments

Comments
 (0)