@replanejs/svelte 0.8.20 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -26
- package/dist/ReplaneContext.svelte +97 -43
- package/dist/ReplaneContext.svelte.d.ts.map +1 -1
- package/dist/context.d.ts +2 -2
- package/dist/context.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/stores.d.ts +4 -4
- package/dist/stores.d.ts.map +1 -1
- package/dist/types.d.ts +29 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -6
- package/dist/version.d.ts +2 -2
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -17,9 +17,10 @@ npm install @replanejs/svelte
|
|
|
17
17
|
```svelte
|
|
18
18
|
<script>
|
|
19
19
|
import { ReplaneContext, config } from '@replanejs/svelte';
|
|
20
|
-
import {
|
|
20
|
+
import { Replane } from '@replanejs/svelte';
|
|
21
21
|
|
|
22
|
-
const replane =
|
|
22
|
+
const replane = new Replane();
|
|
23
|
+
await replane.connect({
|
|
23
24
|
baseUrl: 'https://your-replane-server.com',
|
|
24
25
|
sdkKey: 'your-sdk-key',
|
|
25
26
|
});
|
|
@@ -45,20 +46,33 @@ npm install @replanejs/svelte
|
|
|
45
46
|
{/if}
|
|
46
47
|
```
|
|
47
48
|
|
|
48
|
-
##
|
|
49
|
+
## Provider Props
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
| Prop | Type | Required | Description |
|
|
52
|
+
| ------------ | --------------------------- | -------- | ------------------------------------------------------- |
|
|
53
|
+
| `connection` | `ConnectOptions \| null` | Yes | Connection options (see below), or `null` to skip connection |
|
|
54
|
+
| `defaults` | `Record<string, unknown>` | No | Default values if server is unavailable |
|
|
55
|
+
| `context` | `Record<string, unknown>` | No | Default context for override evaluations |
|
|
56
|
+
| `snapshot` | `ReplaneSnapshot` | No | Snapshot for SSR hydration |
|
|
57
|
+
| `logger` | `ReplaneLogger` | No | Custom logger (default: console) |
|
|
58
|
+
| `loader` | `Snippet` | No | Snippet to show while loading |
|
|
59
|
+
| `async` | `boolean` | No | Connect asynchronously (renders immediately with defaults) |
|
|
51
60
|
|
|
52
|
-
|
|
53
|
-
| ------------------------- | ---------------------- | -------- | ------------------------------------------ |
|
|
54
|
-
| `baseUrl` | `string` | Yes | Replane server URL |
|
|
55
|
-
| `sdkKey` | `string` | Yes | SDK key for authentication |
|
|
56
|
-
| `context` | `Record<string, any>` | No | Default context for override evaluations |
|
|
57
|
-
| `defaults` | `Record<string, any>` | No | Default values if server is unavailable |
|
|
58
|
-
| `required` | `string[]` or `object` | No | Configs that must exist for initialization |
|
|
59
|
-
| `initializationTimeoutMs` | `number` | No | SDK initialization timeout (default: 5000) |
|
|
61
|
+
## Connection Options
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
The `connection` prop accepts the following options:
|
|
64
|
+
|
|
65
|
+
| Option | Type | Required | Description |
|
|
66
|
+
| --------------------- | --------------------- | -------- | ---------------------------------------- |
|
|
67
|
+
| `baseUrl` | `string` | Yes | Replane server URL |
|
|
68
|
+
| `sdkKey` | `string` | Yes | SDK key for authentication |
|
|
69
|
+
| `connectTimeoutMs` | `number` | No | SDK connection timeout (default: 5000) |
|
|
70
|
+
| `requestTimeoutMs` | `number` | No | Timeout for SSE requests (default: 2000) |
|
|
71
|
+
| `retryDelayMs` | `number` | No | Base delay between retries (default: 200)|
|
|
72
|
+
| `inactivityTimeoutMs` | `number` | No | SSE inactivity timeout (default: 30000) |
|
|
73
|
+
| `fetchFn` | `typeof fetch` | No | Custom fetch implementation |
|
|
74
|
+
|
|
75
|
+
See [`@replanejs/sdk` documentation](https://github.com/replane-dev/replane-javascript/tree/main/packages/sdk#api) for more details.
|
|
62
76
|
|
|
63
77
|
## API
|
|
64
78
|
|
|
@@ -125,15 +139,16 @@ Create a reactive store from a client directly (without context). Type-safe with
|
|
|
125
139
|
|
|
126
140
|
Context component that makes the Replane client available to your component tree.
|
|
127
141
|
|
|
128
|
-
Can be used in
|
|
142
|
+
Can be used in several ways:
|
|
129
143
|
|
|
130
144
|
**1. With a pre-created client:**
|
|
131
145
|
|
|
132
146
|
```svelte
|
|
133
147
|
<script>
|
|
134
|
-
import { ReplaneContext,
|
|
148
|
+
import { ReplaneContext, Replane } from '@replanejs/svelte';
|
|
135
149
|
|
|
136
|
-
const replane =
|
|
150
|
+
const replane = new Replane();
|
|
151
|
+
await replane.connect({
|
|
137
152
|
baseUrl: 'https://your-replane-server.com',
|
|
138
153
|
sdkKey: 'your-sdk-key',
|
|
139
154
|
});
|
|
@@ -144,20 +159,20 @@ Can be used in three ways:
|
|
|
144
159
|
</ReplaneContext>
|
|
145
160
|
```
|
|
146
161
|
|
|
147
|
-
**2. With
|
|
162
|
+
**2. With connection (client managed internally):**
|
|
148
163
|
|
|
149
164
|
```svelte
|
|
150
165
|
<script>
|
|
151
166
|
import { ReplaneContext } from '@replanejs/svelte';
|
|
152
167
|
|
|
153
|
-
const
|
|
168
|
+
const connection = {
|
|
154
169
|
baseUrl: 'https://your-replane-server.com',
|
|
155
170
|
sdkKey: 'your-sdk-key',
|
|
156
171
|
};
|
|
157
172
|
</script>
|
|
158
173
|
|
|
159
174
|
<svelte:boundary onerror={(e) => console.error(e)}>
|
|
160
|
-
<ReplaneContext {
|
|
175
|
+
<ReplaneContext {connection}>
|
|
161
176
|
<App />
|
|
162
177
|
|
|
163
178
|
{#snippet loader()}
|
|
@@ -171,7 +186,30 @@ Can be used in three ways:
|
|
|
171
186
|
</svelte:boundary>
|
|
172
187
|
```
|
|
173
188
|
|
|
174
|
-
**3. With
|
|
189
|
+
**3. With async mode:**
|
|
190
|
+
|
|
191
|
+
Connect in the background while rendering immediately with defaults:
|
|
192
|
+
|
|
193
|
+
```svelte
|
|
194
|
+
<script>
|
|
195
|
+
import { ReplaneContext } from '@replanejs/svelte';
|
|
196
|
+
|
|
197
|
+
const connection = {
|
|
198
|
+
baseUrl: 'https://your-replane-server.com',
|
|
199
|
+
sdkKey: 'your-sdk-key',
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const defaults = {
|
|
203
|
+
featureEnabled: false,
|
|
204
|
+
};
|
|
205
|
+
</script>
|
|
206
|
+
|
|
207
|
+
<ReplaneContext {connection} {defaults} async>
|
|
208
|
+
<App />
|
|
209
|
+
</ReplaneContext>
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**4. With a snapshot (for SSR/hydration):**
|
|
175
213
|
|
|
176
214
|
```svelte
|
|
177
215
|
<script>
|
|
@@ -179,13 +217,13 @@ Can be used in three ways:
|
|
|
179
217
|
|
|
180
218
|
let { data, children } = $props();
|
|
181
219
|
|
|
182
|
-
const
|
|
220
|
+
const connection = {
|
|
183
221
|
baseUrl: import.meta.env.VITE_REPLANE_BASE_URL,
|
|
184
222
|
sdkKey: import.meta.env.VITE_REPLANE_SDK_KEY,
|
|
185
223
|
};
|
|
186
224
|
</script>
|
|
187
225
|
|
|
188
|
-
<ReplaneContext {
|
|
226
|
+
<ReplaneContext {connection} snapshot={data.replaneSnapshot}>
|
|
189
227
|
{@render children()}
|
|
190
228
|
</ReplaneContext>
|
|
191
229
|
```
|
|
@@ -235,8 +273,10 @@ import { getReplaneSnapshot } from "@replanejs/svelte";
|
|
|
235
273
|
|
|
236
274
|
export async function load() {
|
|
237
275
|
const snapshot = await getReplaneSnapshot({
|
|
238
|
-
|
|
239
|
-
|
|
276
|
+
connection: {
|
|
277
|
+
baseUrl: import.meta.env.REPLANE_BASE_URL,
|
|
278
|
+
sdkKey: import.meta.env.REPLANE_SDK_KEY,
|
|
279
|
+
},
|
|
240
280
|
});
|
|
241
281
|
|
|
242
282
|
return { replaneSnapshot: snapshot };
|
|
@@ -250,13 +290,13 @@ export async function load() {
|
|
|
250
290
|
|
|
251
291
|
let { data, children } = $props();
|
|
252
292
|
|
|
253
|
-
const
|
|
293
|
+
const connection = {
|
|
254
294
|
baseUrl: import.meta.env.VITE_REPLANE_BASE_URL,
|
|
255
295
|
sdkKey: import.meta.env.VITE_REPLANE_SDK_KEY,
|
|
256
296
|
};
|
|
257
297
|
</script>
|
|
258
298
|
|
|
259
|
-
<ReplaneContext {
|
|
299
|
+
<ReplaneContext {connection} snapshot={data.replaneSnapshot}>
|
|
260
300
|
{@render children()}
|
|
261
301
|
</ReplaneContext>
|
|
262
302
|
```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
import type {
|
|
2
|
+
import type { Replane } from "@replanejs/sdk";
|
|
3
3
|
import type {
|
|
4
4
|
ReplaneContextProps,
|
|
5
5
|
ReplaneContextWithClientProps,
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
17
|
<script lang="ts" generics="T extends object">
|
|
18
|
-
import {
|
|
18
|
+
import { Replane as ReplaneClass } from "@replanejs/sdk";
|
|
19
19
|
import { setReplaneContext } from "./context";
|
|
20
20
|
import { hasClient } from "./types";
|
|
21
21
|
|
|
@@ -23,62 +23,115 @@
|
|
|
23
23
|
|
|
24
24
|
type ClientState =
|
|
25
25
|
| { status: "loading"; client: null; error: null }
|
|
26
|
-
| { status: "ready"; client:
|
|
26
|
+
| { status: "ready"; client: Replane<T>; error: null }
|
|
27
27
|
| { status: "error"; client: null; error: Error };
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// Determine if we're in sync mode (client available immediately)
|
|
30
|
+
// This must be computed during initialization, not reactively
|
|
31
|
+
function computeInitialState(): {
|
|
32
|
+
state: ClientState;
|
|
33
|
+
client: Replane<T> | null;
|
|
34
|
+
isSyncMode: boolean;
|
|
35
|
+
} {
|
|
36
|
+
// Pre-created client - use directly
|
|
37
|
+
if (hasClient(props)) {
|
|
38
|
+
return {
|
|
39
|
+
state: { status: "ready", client: props.client, error: null },
|
|
40
|
+
client: props.client,
|
|
41
|
+
isSyncMode: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { connection, snapshot, context, logger, defaults } = props;
|
|
46
|
+
const isAsync = props.async;
|
|
47
|
+
|
|
48
|
+
// Sync mode: snapshot, no connection, or async flag
|
|
49
|
+
if (snapshot || !connection || isAsync) {
|
|
50
|
+
try {
|
|
51
|
+
const client = new ReplaneClass<T>({
|
|
52
|
+
snapshot,
|
|
53
|
+
logger,
|
|
54
|
+
context,
|
|
55
|
+
defaults,
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
state: { status: "ready", client, error: null },
|
|
59
|
+
client,
|
|
60
|
+
isSyncMode: true,
|
|
61
|
+
};
|
|
62
|
+
} catch (err) {
|
|
63
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
64
|
+
return {
|
|
65
|
+
state: { status: "error", client: null, error },
|
|
66
|
+
client: null,
|
|
67
|
+
isSyncMode: true,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Loading mode: need to wait for connection
|
|
73
|
+
return {
|
|
74
|
+
state: { status: "loading", client: null, error: null },
|
|
75
|
+
client: null,
|
|
76
|
+
isSyncMode: false,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Compute initial state synchronously during component initialization
|
|
81
|
+
const initialState = computeInitialState();
|
|
82
|
+
let state = $state<ClientState>(initialState.state);
|
|
83
|
+
let clientRef: Replane<T> | null = initialState.client;
|
|
84
|
+
|
|
85
|
+
// Set context immediately for sync mode (during initialization)
|
|
86
|
+
if (initialState.isSyncMode && initialState.client) {
|
|
87
|
+
setReplaneContext<T>(initialState.client);
|
|
88
|
+
}
|
|
89
|
+
|
|
31
90
|
let cancelled = false;
|
|
32
91
|
|
|
33
|
-
// Handle
|
|
92
|
+
// Handle async connection for sync mode, or full async flow for loading mode
|
|
34
93
|
$effect(() => {
|
|
35
94
|
cancelled = false;
|
|
36
95
|
|
|
37
96
|
if (hasClient(props)) {
|
|
38
|
-
// Pre-created client -
|
|
39
|
-
state = { status: "ready", client: props.client, error: null };
|
|
97
|
+
// Pre-created client - already set up synchronously
|
|
40
98
|
return;
|
|
41
99
|
}
|
|
42
100
|
|
|
43
|
-
|
|
44
|
-
const { options, snapshot } = props;
|
|
101
|
+
const { connection, logger } = props;
|
|
45
102
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
agent: options.agent ?? DEFAULT_AGENT,
|
|
60
|
-
},
|
|
61
|
-
context: options.context,
|
|
103
|
+
// Get connection options with default agent
|
|
104
|
+
const connectionWithAgent = connection
|
|
105
|
+
? {
|
|
106
|
+
...connection,
|
|
107
|
+
agent: connection.agent ?? DEFAULT_AGENT,
|
|
108
|
+
}
|
|
109
|
+
: undefined;
|
|
110
|
+
|
|
111
|
+
if (initialState.isSyncMode) {
|
|
112
|
+
// Sync mode - client already created, just need to connect in background
|
|
113
|
+
if (connectionWithAgent && clientRef) {
|
|
114
|
+
clientRef.connect(connectionWithAgent).catch((err) => {
|
|
115
|
+
(logger ?? console)?.error("Failed to connect Replane client", err);
|
|
62
116
|
});
|
|
63
|
-
clientRef = client;
|
|
64
|
-
state = { status: "ready", client, error: null };
|
|
65
|
-
} catch (err) {
|
|
66
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
67
|
-
state = { status: "error", client: null, error };
|
|
68
117
|
}
|
|
69
118
|
return;
|
|
70
119
|
}
|
|
71
120
|
|
|
72
|
-
//
|
|
73
|
-
|
|
121
|
+
// Loading mode - create client and connect
|
|
122
|
+
const { context, defaults } = props;
|
|
123
|
+
|
|
124
|
+
const client = new ReplaneClass<T>({
|
|
125
|
+
logger,
|
|
126
|
+
context,
|
|
127
|
+
defaults,
|
|
128
|
+
});
|
|
74
129
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
})
|
|
79
|
-
.then((client) => {
|
|
130
|
+
client
|
|
131
|
+
.connect(connectionWithAgent!)
|
|
132
|
+
.then(() => {
|
|
80
133
|
if (cancelled) {
|
|
81
|
-
client.
|
|
134
|
+
client.disconnect();
|
|
82
135
|
return;
|
|
83
136
|
}
|
|
84
137
|
clientRef = client;
|
|
@@ -92,17 +145,18 @@
|
|
|
92
145
|
|
|
93
146
|
return () => {
|
|
94
147
|
cancelled = true;
|
|
95
|
-
// Only
|
|
148
|
+
// Only disconnect client if we created it (not pre-created)
|
|
96
149
|
if (clientRef && !hasClient(props)) {
|
|
97
|
-
clientRef.
|
|
150
|
+
clientRef.disconnect();
|
|
98
151
|
clientRef = null;
|
|
99
152
|
}
|
|
100
153
|
};
|
|
101
154
|
});
|
|
102
155
|
|
|
103
|
-
// Set context when client
|
|
156
|
+
// Set context when client becomes ready in loading mode
|
|
157
|
+
// This uses $effect.pre to run before children render
|
|
104
158
|
$effect(() => {
|
|
105
|
-
if (state.status === "ready" && state.client) {
|
|
159
|
+
if (!initialState.isSyncMode && state.status === "ready" && state.client) {
|
|
106
160
|
setReplaneContext<T>(state.client);
|
|
107
161
|
}
|
|
108
162
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReplaneContext.svelte.d.ts","sourceRoot":"","sources":["../src/ReplaneContext.svelte.ts"],"names":[],"mappings":"AAIE,OAAO,KAAK,EACV,mBAAmB,EACnB,6BAA6B,EAC7B,8BAA8B,EAC/B,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,mBAAmB,EACnB,6BAA6B,EAC7B,8BAA8B,GAC/B,CAAC;AAMJ,iBAAS,QAAQ,CAAC,CAAC,SAAS,MAAM;
|
|
1
|
+
{"version":3,"file":"ReplaneContext.svelte.d.ts","sourceRoot":"","sources":["../src/ReplaneContext.svelte.ts"],"names":[],"mappings":"AAIE,OAAO,KAAK,EACV,mBAAm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,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1I,YAAY,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;CACjE;AACD,QAAA,MAAM,cAAc,EAAE,qBAAmC,CAAC;AACxC,KAAK,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,YAAY,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AACjF,eAAe,cAAc,CAAC"}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Replane } from "@replanejs/sdk";
|
|
2
2
|
import type { ReplaneContextValue } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Set the Replane client in Svelte context.
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
|
-
export declare function setReplaneContext<T extends object>(client:
|
|
7
|
+
export declare function setReplaneContext<T extends object>(client: Replane<T>): void;
|
|
8
8
|
/**
|
|
9
9
|
* Get the Replane context from Svelte context.
|
|
10
10
|
* @internal
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAInD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAG5E;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACvC,mBAAmB,CAAC,CAAC,CAAC,CAM1B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAO3C"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { default as ReplaneContext } from "./ReplaneContext.svelte";
|
|
2
2
|
export { getReplane, config, configFrom, createTypedReplane, createTypedConfig } from "./stores";
|
|
3
3
|
export { setReplaneContext, getReplaneContext, hasReplaneContext } from "./context";
|
|
4
|
-
export {
|
|
5
|
-
export type {
|
|
4
|
+
export { Replane, getReplaneSnapshot, ReplaneError, ReplaneErrorCode } from "@replanejs/sdk";
|
|
5
|
+
export type { ReplaneSnapshot, ReplaneContext as ReplaneContextType, ReplaneLogger, ReplaneOptions, ConnectOptions, GetConfigOptions, GetReplaneSnapshotOptions, } from "@replanejs/sdk";
|
|
6
6
|
export type { ReplaneContextValue, ReplaneContextProps, ReplaneContextWithClientProps, ReplaneContextWithOptionsProps, } from "./types";
|
|
7
|
-
export { hasClient
|
|
7
|
+
export { hasClient } from "./types";
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGpE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGjG,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAGpF,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGpE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGjG,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAGpF,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE7F,YAAY,EACV,eAAe,EACf,cAAc,IAAI,kBAAkB,EACpC,aAAa,EACb,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,6BAA6B,EAC7B,8BAA8B,GAC/B,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,6 @@ export { getReplane, config, configFrom, createTypedReplane, createTypedConfig }
|
|
|
5
5
|
// Context utilities (for advanced use cases)
|
|
6
6
|
export { setReplaneContext, getReplaneContext, hasReplaneContext } from "./context";
|
|
7
7
|
// Re-export from SDK for convenience
|
|
8
|
-
export {
|
|
8
|
+
export { Replane, getReplaneSnapshot, ReplaneError, ReplaneErrorCode } from "@replanejs/sdk";
|
|
9
9
|
// Type guards
|
|
10
|
-
export { hasClient
|
|
10
|
+
export { hasClient } from "./types";
|
package/dist/stores.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Readable } from "svelte/store";
|
|
2
|
-
import type { GetConfigOptions,
|
|
2
|
+
import type { GetConfigOptions, Replane } from "@replanejs/sdk";
|
|
3
3
|
/**
|
|
4
4
|
* Get the Replane client from context.
|
|
5
5
|
*
|
|
@@ -18,7 +18,7 @@ import type { GetConfigOptions, ReplaneClient } from "@replanejs/sdk";
|
|
|
18
18
|
* </script>
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
export declare function getReplane<T extends Record<string, unknown> = any>():
|
|
21
|
+
export declare function getReplane<T extends Record<string, unknown> = any>(): Replane<T>;
|
|
22
22
|
/**
|
|
23
23
|
* Create a reactive store for a specific config value.
|
|
24
24
|
*
|
|
@@ -71,7 +71,7 @@ export declare function config<T>(name: string, options?: GetConfigOptions<T>):
|
|
|
71
71
|
* {/if}
|
|
72
72
|
* ```
|
|
73
73
|
*/
|
|
74
|
-
export declare function configFrom<TConfigs extends Record<string, unknown>, K extends keyof TConfigs>(replane:
|
|
74
|
+
export declare function configFrom<TConfigs extends Record<string, unknown>, K extends keyof TConfigs>(replane: Replane<TConfigs>, name: K, options?: GetConfigOptions<TConfigs[K]>): Readable<TConfigs[K]>;
|
|
75
75
|
/**
|
|
76
76
|
* Creates a typed version of getReplane().
|
|
77
77
|
*
|
|
@@ -101,7 +101,7 @@ export declare function configFrom<TConfigs extends Record<string, unknown>, K e
|
|
|
101
101
|
* </script>
|
|
102
102
|
* ```
|
|
103
103
|
*/
|
|
104
|
-
export declare function createTypedReplane<TConfigs extends Record<string, unknown>>(): () =>
|
|
104
|
+
export declare function createTypedReplane<TConfigs extends Record<string, unknown>>(): () => Replane<TConfigs>;
|
|
105
105
|
/**
|
|
106
106
|
* Creates a typed version of config().
|
|
107
107
|
*
|
package/dist/stores.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stores.d.ts","sourceRoot":"","sources":["../src/stores.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"stores.d.ts","sourceRoot":"","sources":["../src/stores.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC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
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Replane, ReplaneSnapshot, ReplaneContext as ReplaneContextType, ReplaneLogger, ConnectOptions } from "@replanejs/sdk";
|
|
2
2
|
import type { Snippet } from "svelte";
|
|
3
3
|
/**
|
|
4
4
|
* Context value containing the Replane client
|
|
5
5
|
*/
|
|
6
6
|
export interface ReplaneContextValue<T extends object = Record<string, unknown>> {
|
|
7
|
-
client:
|
|
7
|
+
client: Replane<T>;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Props for ReplaneContext when using a pre-created client.
|
|
11
11
|
*/
|
|
12
12
|
export interface ReplaneContextWithClientProps<T extends object = Record<string, unknown>> {
|
|
13
|
-
/** Pre-created
|
|
14
|
-
client:
|
|
13
|
+
/** Pre-created Replane client instance */
|
|
14
|
+
client: Replane<T>;
|
|
15
15
|
/** Children snippet */
|
|
16
16
|
children: Snippet;
|
|
17
17
|
}
|
|
@@ -19,15 +19,31 @@ export interface ReplaneContextWithClientProps<T extends object = Record<string,
|
|
|
19
19
|
* Props for ReplaneContext when letting it manage the client internally.
|
|
20
20
|
*/
|
|
21
21
|
export interface ReplaneContextWithOptionsProps<T extends object = Record<string, unknown>> {
|
|
22
|
-
/** Options to create or restore the ReplaneClient */
|
|
23
|
-
options: ReplaneClientOptions<T>;
|
|
24
22
|
/** Children snippet */
|
|
25
23
|
children: Snippet;
|
|
24
|
+
/**
|
|
25
|
+
* Connection options for connecting to the Replane server.
|
|
26
|
+
* Pass null to explicitly skip connection (client will use defaults/snapshot only).
|
|
27
|
+
*/
|
|
28
|
+
connection: ConnectOptions | null;
|
|
29
|
+
/**
|
|
30
|
+
* Default context for all config evaluations.
|
|
31
|
+
*/
|
|
32
|
+
context?: ReplaneContextType;
|
|
33
|
+
/**
|
|
34
|
+
* Optional logger (defaults to console).
|
|
35
|
+
*/
|
|
36
|
+
logger?: ReplaneLogger;
|
|
37
|
+
/**
|
|
38
|
+
* Default values to use before connection is established.
|
|
39
|
+
*/
|
|
40
|
+
defaults?: {
|
|
41
|
+
[K in keyof T]?: T[K];
|
|
42
|
+
};
|
|
26
43
|
/**
|
|
27
44
|
* Optional snapshot from server-side rendering.
|
|
28
45
|
* When provided, the client will be restored from the snapshot synchronously
|
|
29
46
|
* instead of fetching configs from the server.
|
|
30
|
-
* The `options` will be used for live updates connection if provided.
|
|
31
47
|
*/
|
|
32
48
|
snapshot?: ReplaneSnapshot<T>;
|
|
33
49
|
/**
|
|
@@ -36,14 +52,16 @@ export interface ReplaneContextWithOptionsProps<T extends object = Record<string
|
|
|
36
52
|
* Ignored when snapshot is provided (restoration is synchronous).
|
|
37
53
|
*/
|
|
38
54
|
loader?: Snippet;
|
|
55
|
+
/**
|
|
56
|
+
* If true, the client will be connected asynchronously.
|
|
57
|
+
* Make sure to provide defaults or snapshot.
|
|
58
|
+
* @default false
|
|
59
|
+
*/
|
|
60
|
+
async?: boolean;
|
|
39
61
|
}
|
|
40
62
|
export type ReplaneContextProps<T extends object = Record<string, unknown>> = ReplaneContextWithClientProps<T> | ReplaneContextWithOptionsProps<T>;
|
|
41
63
|
/**
|
|
42
64
|
* Type guard to check if props contain a pre-created client.
|
|
43
65
|
*/
|
|
44
66
|
export declare function hasClient<T extends object>(props: ReplaneContextProps<T>): props is ReplaneContextWithClientProps<T>;
|
|
45
|
-
/**
|
|
46
|
-
* Type guard to check if props contain options (with or without snapshot).
|
|
47
|
-
*/
|
|
48
|
-
export declare function hasOptions<T extends object>(props: ReplaneContextProps<T>): props is ReplaneContextWithOptionsProps<T>;
|
|
49
67
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,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6BAA6B,CAAC,CAAC,CAAC,GAChC,8BAA8B,CAAC,CAAC,CAAC,CAAC;AAEtC;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EACxC,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAC5B,KAAK,IAAI,6BAA6B,CAAC,CAAC,CAAC,CAE3C"}
|
package/dist/types.js
CHANGED
|
@@ -4,9 +4,3 @@
|
|
|
4
4
|
export function hasClient(props) {
|
|
5
5
|
return "client" in props && props.client !== undefined;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
* Type guard to check if props contain options (with or without snapshot).
|
|
9
|
-
*/
|
|
10
|
-
export function hasOptions(props) {
|
|
11
|
-
return "options" in props && props.options !== undefined;
|
|
12
|
-
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
2
|
-
export declare const DEFAULT_AGENT = "replane-js-svelte/0.
|
|
1
|
+
export declare const VERSION = "0.9.2";
|
|
2
|
+
export declare const DEFAULT_AGENT = "replane-js-svelte/0.9.2";
|
|
3
3
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,aAAa,4BAAiC,CAAC"}
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@replanejs/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "Svelte SDK for Replane - feature flags and remote configuration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"svelte": "./dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"svelte": ">=4.0.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@replanejs/sdk": "^0.
|
|
42
|
+
"@replanejs/sdk": "^0.9.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@sveltejs/package": "^2.3.10",
|