Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7c3d36

Browse files
committed
feat: add in memory client
1 parent 500cae3 commit a7c3d36

File tree

11 files changed

+707
-19
lines changed

11 files changed

+707
-19
lines changed

packages/next/src/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export {
9191
Replane,
9292
ReplaneError,
9393
ReplaneErrorCode,
94+
InMemoryReplaneClient,
9495
} from "@replanejs/react";
9596

9697
export type {
@@ -104,4 +105,8 @@ export type {
104105
ReplaneOptions,
105106
ConnectOptions,
106107
GetConfigOptions,
108+
InMemoryReplaneClientOptions,
109+
SetConfigOptions,
110+
Override,
111+
Condition,
107112
} from "@replanejs/react";

packages/react/src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ export type {
1010
} from "./types";
1111

1212
// Re-export from SDK
13-
export { Replane, getReplaneSnapshot, ReplaneError, ReplaneErrorCode } from "@replanejs/sdk";
13+
export {
14+
Replane,
15+
getReplaneSnapshot,
16+
ReplaneError,
17+
ReplaneErrorCode,
18+
InMemoryReplaneClient,
19+
} from "@replanejs/sdk";
1420
export type {
1521
ReplaneSnapshot,
1622
ReplaneContext,
@@ -19,4 +25,8 @@ export type {
1925
ConnectOptions,
2026
GetConfigOptions,
2127
GetReplaneSnapshotOptions,
28+
InMemoryReplaneClientOptions,
29+
SetConfigOptions,
30+
Override,
31+
Condition,
2232
} from "@replanejs/sdk";

packages/sdk/src/client-types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RenderedOverride } from "./types";
1+
import type { Override } from "./types";
22

33
/**
44
* Context object for override evaluation.
@@ -50,7 +50,7 @@ export interface ReplaneSnapshot<_T extends object = object> {
5050
configs: Array<{
5151
name: string;
5252
value: unknown;
53-
overrides: RenderedOverride[];
53+
overrides: Override[];
5454
}>;
5555
}
5656

@@ -159,5 +159,5 @@ export interface ConnectFinalOptions {
159159
export interface InitialConfig {
160160
name: string;
161161
value: unknown;
162-
overrides: RenderedOverride[];
162+
overrides: Override[];
163163
}

packages/sdk/src/client.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,13 @@ class ReplaneImpl<T extends object = Record<string, unknown>> {
360360
});
361361

362362
for await (const event of replicationStream) {
363-
const updatedConfigs: ConfigDto[] =
364-
event.type === "config_change" ? [event.config] : event.configs;
365-
this.processConfigUpdates(updatedConfigs);
363+
if (event.type === "init") {
364+
this.processConfigUpdates(event.configs);
365+
this.logger.info(`Replane: initialized with ${event.configs.length} config(s)`);
366+
} else {
367+
this.processConfigUpdates([event.config]);
368+
this.logger.info(`Replane: config "${event.config.name}" updated`);
369+
}
366370
clientReady.resolve();
367371
}
368372
} catch (error) {

packages/sdk/src/evaluation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RenderedCondition, RenderedOverride } from "./types";
1+
import type { Condition, Override } from "./types";
22
import type { ReplaneContext, ReplaneLogger } from "./client-types";
33
import { fnv1a32ToUnit } from "./hash";
44

@@ -19,7 +19,7 @@ export type EvaluationResult = "matched" | "not_matched" | "unknown";
1919
*/
2020
export function evaluateOverrides<T>(
2121
baseValue: T,
22-
overrides: RenderedOverride[],
22+
overrides: Override[],
2323
context: ReplaneContext,
2424
logger: ReplaneLogger
2525
): T {
@@ -53,7 +53,7 @@ export function evaluateOverrides<T>(
5353
* @returns The evaluation result
5454
*/
5555
export function evaluateCondition(
56-
condition: RenderedCondition,
56+
condition: Condition,
5757
context: ReplaneContext,
5858
logger: ReplaneLogger
5959
): EvaluationResult {

0 commit comments

Comments
 (0)