@lunora/svelte 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +2 -0
- package/__assets__/package-og.svg +1 -1
- package/dist/index.d.mts +73 -3
- package/dist/index.d.ts +73 -3
- package/dist/index.mjs +11 -9
- package/dist/packem_shared/{auth-D8EV6u02.mjs → auth-DLPf_bK9.mjs} +1 -1
- package/dist/packem_shared/{connectionStatus-CROr6jbn.mjs → connectionStatus-CRsOMeYl.mjs} +1 -1
- package/dist/packem_shared/flag-19nEeKPT.mjs +56 -0
- package/dist/packem_shared/{hydratePreloaded-BUv3k4-s.mjs → hydratePreloaded-D5rUJdXy.mjs} +1 -1
- package/dist/packem_shared/{paginatedQuery-CfCSITZv.mjs → infiniteQuery-jPMQw8Vz.mjs} +1 -1
- package/dist/packem_shared/{mutation-CA3qEPCB.mjs → mutation-CnDkAaLH.mjs} +1 -1
- package/dist/packem_shared/mutator-B5LchgMS.mjs +19 -0
- package/dist/packem_shared/{presence-Bf-y7QzR.mjs → presence-BQWixJ2T.mjs} +1 -1
- package/dist/packem_shared/{query-B14VE2Qg.mjs → query-D8Pct9Qe.mjs} +1 -1
- package/dist/packem_shared/{subscription-B3HDNcpq.mjs → subscription-twuBT_Wb.mjs} +1 -1
- package/package.json +5 -5
- /package/dist/packem_shared/{setLunoraClient--bwSz7F6.mjs → getLunoraClient--bwSz7F6.mjs} +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LunoraClient, User, ConnectionStatus, Preloaded, FunctionReference, ReturnOf, ArgsOf, MutationCallOptions, SubscriptionErrorCallback } from '@lunora/client';
|
|
2
|
-
export type { ArgsOf, ConnectionStatus, FunctionReference, LunoraClient, MutationCallOptions, Preloaded, ReturnOf } from '@lunora/client';
|
|
1
|
+
import { LunoraClient, User, ConnectionStatus, Preloaded, FunctionReference, ReturnOf, ArgsOf, MutationCallOptions, MutatorHandle, SubscriptionErrorCallback } from '@lunora/client';
|
|
2
|
+
export type { ArgsOf, ConnectionStatus, FunctionReference, LunoraClient, MutationCallOptions, MutatorHandle, MutatorTransaction, Preloaded, ReturnOf } from '@lunora/client';
|
|
3
3
|
import { Readable } from 'svelte/store';
|
|
4
4
|
import { PaginationStatus } from '@lunora/client/pagination';
|
|
5
5
|
import { RateLimitStatus, RateLimitConfig } from '@lunora/ratelimit';
|
|
@@ -60,6 +60,45 @@ type ConnectionStatusStore = Readable<ConnectionStatus>;
|
|
|
60
60
|
* before this runs).
|
|
61
61
|
*/
|
|
62
62
|
declare const connectionStatus: (client?: LunoraClient) => ConnectionStatusStore;
|
|
63
|
+
/** A targeting context merged on top of the app's default (`defineFlags({ identify })`). */
|
|
64
|
+
type FlagContext = Record<string, unknown>;
|
|
65
|
+
/** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
|
|
66
|
+
type FlagValue = boolean | number | string | {
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
} | unknown[] | null;
|
|
69
|
+
/**
|
|
70
|
+
* Open a single feature flag as a Svelte readable store, live over Lunora's
|
|
71
|
+
* WebSocket. Read it with the `$store` idiom (`{$darkMode}`).
|
|
72
|
+
*
|
|
73
|
+
* The store holds `defaultValue` until the first evaluation lands, then the
|
|
74
|
+
* server's resolved value — re-emitted whenever the provider re-evaluates (e.g. a
|
|
75
|
+
* flag is toggled in Cloudflare Flagship). The flag's kind is inferred from
|
|
76
|
+
* `defaultValue`'s runtime type, so `flag("dark", false)` reads a boolean and
|
|
77
|
+
* `flag("hero", "control")` a string. `context` supplies a per-call targeting
|
|
78
|
+
* context merged on top of the app's default `identify` targeting key.
|
|
79
|
+
*
|
|
80
|
+
* The subscription opens lazily on the first `$`-read and tears down when the
|
|
81
|
+
* last subscriber detaches. Pass `client` explicitly, or omit it to resolve the
|
|
82
|
+
* ambient client published by `setLunoraClient`. Evaluation never throws — a
|
|
83
|
+
* provider error resolves the default (the same fail-open contract as `ctx.flags`).
|
|
84
|
+
*/
|
|
85
|
+
declare function flag<T extends FlagValue>(key: string, defaultValue: T, context?: FlagContext): Readable<T>;
|
|
86
|
+
declare function flag<T extends FlagValue>(client: LunoraClient, key: string, defaultValue: T, context?: FlagContext): Readable<T>;
|
|
87
|
+
/**
|
|
88
|
+
* Open several feature flags at once as a single Svelte readable store of the
|
|
89
|
+
* resolved record, live over Lunora's WebSocket.
|
|
90
|
+
*
|
|
91
|
+
* Pass a record of `key → defaultValue`; each flag's kind is inferred from its
|
|
92
|
+
* default, and the store holds the same-shaped record with resolved values (the
|
|
93
|
+
* defaults until each evaluation lands). A single `context` applies to every
|
|
94
|
+
* flag. This is the batched form of {@link flag} — one store, one subscription
|
|
95
|
+
* per key, torn down together when the last subscriber detaches.
|
|
96
|
+
*
|
|
97
|
+
* Pass `client` explicitly, or omit it to resolve the ambient client published
|
|
98
|
+
* by `setLunoraClient`.
|
|
99
|
+
*/
|
|
100
|
+
declare function flags<T extends Record<string, FlagValue>>(flagDefaults: T, context?: FlagContext): Readable<T>;
|
|
101
|
+
declare function flags<T extends Record<string, FlagValue>>(client: LunoraClient, flagDefaults: T, context?: FlagContext): Readable<T>;
|
|
63
102
|
/**
|
|
64
103
|
* Hydrate a query store from a {@link Preloaded} token produced by
|
|
65
104
|
* `preloadQuery` during SSR, then keep it live — the reactive-loader handoff.
|
|
@@ -121,6 +160,37 @@ interface MutationHandle<F extends FunctionReference> {
|
|
|
121
160
|
*/
|
|
122
161
|
declare function mutation<F extends FunctionReference>(function_: F): MutationHandle<F>;
|
|
123
162
|
declare function mutation<F extends FunctionReference>(client: LunoraClient, function_: F): MutationHandle<F>;
|
|
163
|
+
/**
|
|
164
|
+
* The reactive handle returned by {@link mutator} — the Svelte counterpart to
|
|
165
|
+
* `@lunora/react`'s `useMutator`, re-expressed as stores you read with `$`.
|
|
166
|
+
* `error`/`isError`/`pending` are readable stores and `mutate` is an awaitable
|
|
167
|
+
* that resolves once the write is persisted (or rejects).
|
|
168
|
+
*/
|
|
169
|
+
interface MutatorHandleStore<TArgs> {
|
|
170
|
+
/** The latest invocation's error, or `undefined`. */
|
|
171
|
+
error: Readable<Error | undefined>;
|
|
172
|
+
/** `true` when the latest invocation rejected. */
|
|
173
|
+
isError: Readable<boolean>;
|
|
174
|
+
/** Run the mutator; resolves once the write is persisted, rejects on failure. */
|
|
175
|
+
mutate: (args: TArgs) => Promise<void>;
|
|
176
|
+
/** `true` while ANY invocation from this handle is in flight (ref-counted, so overlapping calls compose). */
|
|
177
|
+
pending: Readable<boolean>;
|
|
178
|
+
/** Clear the latest `error` back to idle. */
|
|
179
|
+
reset: () => void;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
|
|
183
|
+
* custom-mutator handle from `@lunora/db`'s `bindMutators` — the Svelte
|
|
184
|
+
* equivalent of `@lunora/react`'s `useMutator`. The optimistic overlay and
|
|
185
|
+
* server-authoritative push are owned by the bound handle (and TanStack DB's
|
|
186
|
+
* optimistic-transaction layer rebases pending overlays on every sync tick);
|
|
187
|
+
* this helper only surfaces store state for the in-flight/error lifecycle. Reads
|
|
188
|
+
* stay on the existing TanStack `useLiveQuery`; no new query store is needed.
|
|
189
|
+
*
|
|
190
|
+
* `pending` is ref-counted across overlapping invocations of THIS handle, so it
|
|
191
|
+
* clears only once every concurrent call has settled.
|
|
192
|
+
*/
|
|
193
|
+
declare const mutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorHandleStore<TArgs>;
|
|
124
194
|
/** The args a paginated query exposes minus the framework-supplied page cursor. */
|
|
125
195
|
type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOf<F>, "paginationOpts">;
|
|
126
196
|
/** The element type of the `page` array a paginated query returns. */
|
|
@@ -332,4 +402,4 @@ interface SubscriptionHandle<T> {
|
|
|
332
402
|
*/
|
|
333
403
|
declare function subscription<F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip", options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
|
|
334
404
|
declare function subscription<F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F> | "skip", options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
|
|
335
|
-
export { type AuthStore, type ConnectionStatusStore, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type MutationHandle, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type SubscriptionHandle, type SubscriptionStoreOptions, auth, connectionStatus, getLunoraClient, hydratePreloaded, infiniteQuery, mutation, paginatedQuery, presence, query, rateLimit, setLunoraClient, subscription };
|
|
405
|
+
export { type AuthStore, type ConnectionStatusStore, type FlagContext, type FlagValue, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type MutationHandle, type MutatorHandleStore, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type SubscriptionHandle, type SubscriptionStoreOptions, auth, connectionStatus, flag, flags, getLunoraClient, hydratePreloaded, infiniteQuery, mutation, mutator, paginatedQuery, presence, query, rateLimit, setLunoraClient, subscription };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LunoraClient, User, ConnectionStatus, Preloaded, FunctionReference, ReturnOf, ArgsOf, MutationCallOptions, SubscriptionErrorCallback } from '@lunora/client';
|
|
2
|
-
export type { ArgsOf, ConnectionStatus, FunctionReference, LunoraClient, MutationCallOptions, Preloaded, ReturnOf } from '@lunora/client';
|
|
1
|
+
import { LunoraClient, User, ConnectionStatus, Preloaded, FunctionReference, ReturnOf, ArgsOf, MutationCallOptions, MutatorHandle, SubscriptionErrorCallback } from '@lunora/client';
|
|
2
|
+
export type { ArgsOf, ConnectionStatus, FunctionReference, LunoraClient, MutationCallOptions, MutatorHandle, MutatorTransaction, Preloaded, ReturnOf } from '@lunora/client';
|
|
3
3
|
import { Readable } from 'svelte/store';
|
|
4
4
|
import { PaginationStatus } from '@lunora/client/pagination';
|
|
5
5
|
import { RateLimitStatus, RateLimitConfig } from '@lunora/ratelimit';
|
|
@@ -60,6 +60,45 @@ type ConnectionStatusStore = Readable<ConnectionStatus>;
|
|
|
60
60
|
* before this runs).
|
|
61
61
|
*/
|
|
62
62
|
declare const connectionStatus: (client?: LunoraClient) => ConnectionStatusStore;
|
|
63
|
+
/** A targeting context merged on top of the app's default (`defineFlags({ identify })`). */
|
|
64
|
+
type FlagContext = Record<string, unknown>;
|
|
65
|
+
/** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
|
|
66
|
+
type FlagValue = boolean | number | string | {
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
} | unknown[] | null;
|
|
69
|
+
/**
|
|
70
|
+
* Open a single feature flag as a Svelte readable store, live over Lunora's
|
|
71
|
+
* WebSocket. Read it with the `$store` idiom (`{$darkMode}`).
|
|
72
|
+
*
|
|
73
|
+
* The store holds `defaultValue` until the first evaluation lands, then the
|
|
74
|
+
* server's resolved value — re-emitted whenever the provider re-evaluates (e.g. a
|
|
75
|
+
* flag is toggled in Cloudflare Flagship). The flag's kind is inferred from
|
|
76
|
+
* `defaultValue`'s runtime type, so `flag("dark", false)` reads a boolean and
|
|
77
|
+
* `flag("hero", "control")` a string. `context` supplies a per-call targeting
|
|
78
|
+
* context merged on top of the app's default `identify` targeting key.
|
|
79
|
+
*
|
|
80
|
+
* The subscription opens lazily on the first `$`-read and tears down when the
|
|
81
|
+
* last subscriber detaches. Pass `client` explicitly, or omit it to resolve the
|
|
82
|
+
* ambient client published by `setLunoraClient`. Evaluation never throws — a
|
|
83
|
+
* provider error resolves the default (the same fail-open contract as `ctx.flags`).
|
|
84
|
+
*/
|
|
85
|
+
declare function flag<T extends FlagValue>(key: string, defaultValue: T, context?: FlagContext): Readable<T>;
|
|
86
|
+
declare function flag<T extends FlagValue>(client: LunoraClient, key: string, defaultValue: T, context?: FlagContext): Readable<T>;
|
|
87
|
+
/**
|
|
88
|
+
* Open several feature flags at once as a single Svelte readable store of the
|
|
89
|
+
* resolved record, live over Lunora's WebSocket.
|
|
90
|
+
*
|
|
91
|
+
* Pass a record of `key → defaultValue`; each flag's kind is inferred from its
|
|
92
|
+
* default, and the store holds the same-shaped record with resolved values (the
|
|
93
|
+
* defaults until each evaluation lands). A single `context` applies to every
|
|
94
|
+
* flag. This is the batched form of {@link flag} — one store, one subscription
|
|
95
|
+
* per key, torn down together when the last subscriber detaches.
|
|
96
|
+
*
|
|
97
|
+
* Pass `client` explicitly, or omit it to resolve the ambient client published
|
|
98
|
+
* by `setLunoraClient`.
|
|
99
|
+
*/
|
|
100
|
+
declare function flags<T extends Record<string, FlagValue>>(flagDefaults: T, context?: FlagContext): Readable<T>;
|
|
101
|
+
declare function flags<T extends Record<string, FlagValue>>(client: LunoraClient, flagDefaults: T, context?: FlagContext): Readable<T>;
|
|
63
102
|
/**
|
|
64
103
|
* Hydrate a query store from a {@link Preloaded} token produced by
|
|
65
104
|
* `preloadQuery` during SSR, then keep it live — the reactive-loader handoff.
|
|
@@ -121,6 +160,37 @@ interface MutationHandle<F extends FunctionReference> {
|
|
|
121
160
|
*/
|
|
122
161
|
declare function mutation<F extends FunctionReference>(function_: F): MutationHandle<F>;
|
|
123
162
|
declare function mutation<F extends FunctionReference>(client: LunoraClient, function_: F): MutationHandle<F>;
|
|
163
|
+
/**
|
|
164
|
+
* The reactive handle returned by {@link mutator} — the Svelte counterpart to
|
|
165
|
+
* `@lunora/react`'s `useMutator`, re-expressed as stores you read with `$`.
|
|
166
|
+
* `error`/`isError`/`pending` are readable stores and `mutate` is an awaitable
|
|
167
|
+
* that resolves once the write is persisted (or rejects).
|
|
168
|
+
*/
|
|
169
|
+
interface MutatorHandleStore<TArgs> {
|
|
170
|
+
/** The latest invocation's error, or `undefined`. */
|
|
171
|
+
error: Readable<Error | undefined>;
|
|
172
|
+
/** `true` when the latest invocation rejected. */
|
|
173
|
+
isError: Readable<boolean>;
|
|
174
|
+
/** Run the mutator; resolves once the write is persisted, rejects on failure. */
|
|
175
|
+
mutate: (args: TArgs) => Promise<void>;
|
|
176
|
+
/** `true` while ANY invocation from this handle is in flight (ref-counted, so overlapping calls compose). */
|
|
177
|
+
pending: Readable<boolean>;
|
|
178
|
+
/** Clear the latest `error` back to idle. */
|
|
179
|
+
reset: () => void;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
|
|
183
|
+
* custom-mutator handle from `@lunora/db`'s `bindMutators` — the Svelte
|
|
184
|
+
* equivalent of `@lunora/react`'s `useMutator`. The optimistic overlay and
|
|
185
|
+
* server-authoritative push are owned by the bound handle (and TanStack DB's
|
|
186
|
+
* optimistic-transaction layer rebases pending overlays on every sync tick);
|
|
187
|
+
* this helper only surfaces store state for the in-flight/error lifecycle. Reads
|
|
188
|
+
* stay on the existing TanStack `useLiveQuery`; no new query store is needed.
|
|
189
|
+
*
|
|
190
|
+
* `pending` is ref-counted across overlapping invocations of THIS handle, so it
|
|
191
|
+
* clears only once every concurrent call has settled.
|
|
192
|
+
*/
|
|
193
|
+
declare const mutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorHandleStore<TArgs>;
|
|
124
194
|
/** The args a paginated query exposes minus the framework-supplied page cursor. */
|
|
125
195
|
type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOf<F>, "paginationOpts">;
|
|
126
196
|
/** The element type of the `page` array a paginated query returns. */
|
|
@@ -332,4 +402,4 @@ interface SubscriptionHandle<T> {
|
|
|
332
402
|
*/
|
|
333
403
|
declare function subscription<F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip", options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
|
|
334
404
|
declare function subscription<F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F> | "skip", options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
|
|
335
|
-
export { type AuthStore, type ConnectionStatusStore, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type MutationHandle, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type SubscriptionHandle, type SubscriptionStoreOptions, auth, connectionStatus, getLunoraClient, hydratePreloaded, infiniteQuery, mutation, paginatedQuery, presence, query, rateLimit, setLunoraClient, subscription };
|
|
405
|
+
export { type AuthStore, type ConnectionStatusStore, type FlagContext, type FlagValue, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type MutationHandle, type MutatorHandleStore, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type SubscriptionHandle, type SubscriptionStoreOptions, auth, connectionStatus, flag, flags, getLunoraClient, hydratePreloaded, infiniteQuery, mutation, mutator, paginatedQuery, presence, query, rateLimit, setLunoraClient, subscription };
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
export { auth } from './packem_shared/auth-
|
|
2
|
-
export { connectionStatus } from './packem_shared/connectionStatus-
|
|
3
|
-
export { getLunoraClient, setLunoraClient } from './packem_shared/
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
1
|
+
export { auth } from './packem_shared/auth-DLPf_bK9.mjs';
|
|
2
|
+
export { connectionStatus } from './packem_shared/connectionStatus-CRsOMeYl.mjs';
|
|
3
|
+
export { getLunoraClient, setLunoraClient } from './packem_shared/getLunoraClient--bwSz7F6.mjs';
|
|
4
|
+
export { flag, flags } from './packem_shared/flag-19nEeKPT.mjs';
|
|
5
|
+
export { hydratePreloaded } from './packem_shared/hydratePreloaded-D5rUJdXy.mjs';
|
|
6
|
+
export { mutation } from './packem_shared/mutation-CnDkAaLH.mjs';
|
|
7
|
+
export { mutator } from './packem_shared/mutator-B5LchgMS.mjs';
|
|
8
|
+
export { infiniteQuery, paginatedQuery } from './packem_shared/infiniteQuery-jPMQw8Vz.mjs';
|
|
9
|
+
export { presence } from './packem_shared/presence-BQWixJ2T.mjs';
|
|
10
|
+
export { query } from './packem_shared/query-D8Pct9Qe.mjs';
|
|
9
11
|
export { rateLimit } from './packem_shared/rateLimit-Cdw1kp8t.mjs';
|
|
10
|
-
export { subscription } from './packem_shared/subscription-
|
|
12
|
+
export { subscription } from './packem_shared/subscription-twuBT_Wb.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getIdentityStore } from '@lunora/client/auth';
|
|
2
2
|
import { readable } from 'svelte/store';
|
|
3
|
-
import { getLunoraClient } from './
|
|
3
|
+
import { getLunoraClient } from './getLunoraClient--bwSz7F6.mjs';
|
|
4
4
|
|
|
5
5
|
const auth = (explicitClient) => {
|
|
6
6
|
const client = explicitClient ?? getLunoraClient();
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readable } from 'svelte/store';
|
|
2
|
+
import { getLunoraClient } from './getLunoraClient--bwSz7F6.mjs';
|
|
3
|
+
|
|
4
|
+
const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
|
|
5
|
+
const flagKind = (value) => {
|
|
6
|
+
const kind = typeof value;
|
|
7
|
+
if (kind === "boolean" || kind === "number" || kind === "string") {
|
|
8
|
+
return kind;
|
|
9
|
+
}
|
|
10
|
+
return "object";
|
|
11
|
+
};
|
|
12
|
+
const flagsReference = { __lunoraRef: FLAGS_EVAL_PATH };
|
|
13
|
+
const isClient = (value) => typeof value === "object" && value !== null && typeof value.subscribe === "function";
|
|
14
|
+
const subscribeFlag = (client, key, defaultValue, context, set) => {
|
|
15
|
+
try {
|
|
16
|
+
return client.subscribe(flagsReference, { context, default: defaultValue, key, type: flagKind(defaultValue) }, (next) => {
|
|
17
|
+
set(next);
|
|
18
|
+
});
|
|
19
|
+
} catch {
|
|
20
|
+
return () => {
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
function flag(clientOrKey, keyOrDefault, defaultOrContext, maybeContext) {
|
|
25
|
+
const hasExplicitClient = isClient(clientOrKey);
|
|
26
|
+
const client = hasExplicitClient ? clientOrKey : getLunoraClient();
|
|
27
|
+
const key = hasExplicitClient ? keyOrDefault : clientOrKey;
|
|
28
|
+
const defaultValue = hasExplicitClient ? defaultOrContext : keyOrDefault;
|
|
29
|
+
const context = (hasExplicitClient ? maybeContext : defaultOrContext) ?? void 0;
|
|
30
|
+
return readable(defaultValue, (set) => subscribeFlag(client, key, defaultValue, context, set));
|
|
31
|
+
}
|
|
32
|
+
function flags(clientOrFlags, flagsOrContext, maybeContext) {
|
|
33
|
+
const hasExplicitClient = isClient(clientOrFlags);
|
|
34
|
+
const client = hasExplicitClient ? clientOrFlags : getLunoraClient();
|
|
35
|
+
const flagDefaults = hasExplicitClient ? flagsOrContext : clientOrFlags;
|
|
36
|
+
const context = (hasExplicitClient ? maybeContext : flagsOrContext) ?? void 0;
|
|
37
|
+
return readable(flagDefaults, (set) => {
|
|
38
|
+
let current = { ...flagDefaults };
|
|
39
|
+
const unsubscribes = [];
|
|
40
|
+
for (const [key, defaultValue] of Object.entries(flagDefaults)) {
|
|
41
|
+
unsubscribes.push(
|
|
42
|
+
subscribeFlag(client, key, defaultValue, context, (next) => {
|
|
43
|
+
current = { ...current, [key]: next };
|
|
44
|
+
set(current);
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return () => {
|
|
49
|
+
for (const unsubscribe of unsubscribes) {
|
|
50
|
+
unsubscribe();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { flag, flags };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readable } from 'svelte/store';
|
|
2
|
-
import { getLunoraClient } from './
|
|
2
|
+
import { getLunoraClient } from './getLunoraClient--bwSz7F6.mjs';
|
|
3
3
|
|
|
4
4
|
const hydratePreloaded = (preloaded, client) => {
|
|
5
5
|
const resolvedClient = client ?? getLunoraClient();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { initialPages, derivePaginationStatus, rebalance, applyLoadMore } from '@lunora/client/pagination';
|
|
2
2
|
import { derived, writable, readable } from 'svelte/store';
|
|
3
|
-
import { getLunoraClient } from './
|
|
3
|
+
import { getLunoraClient } from './getLunoraClient--bwSz7F6.mjs';
|
|
4
4
|
import { i as isFunctionReference } from './is-function-reference-ycLAcI79.mjs';
|
|
5
5
|
|
|
6
6
|
const buildPageArgs = (page, baseArgs) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createMutationRunner } from '@lunora/client';
|
|
2
2
|
import { writable } from 'svelte/store';
|
|
3
|
-
import { getLunoraClient } from './
|
|
3
|
+
import { getLunoraClient } from './getLunoraClient--bwSz7F6.mjs';
|
|
4
4
|
|
|
5
5
|
function mutation(clientOrFunction, maybeFunction) {
|
|
6
6
|
const hasExplicitClient = maybeFunction !== void 0;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createMutatorRunner } from '@lunora/client';
|
|
2
|
+
import { writable, derived } from 'svelte/store';
|
|
3
|
+
|
|
4
|
+
const mutator = (handle) => {
|
|
5
|
+
const error = writable();
|
|
6
|
+
const pending = writable(false);
|
|
7
|
+
const isError = derived(error, ($error) => $error !== void 0);
|
|
8
|
+
const { mutate, reset } = createMutatorRunner(handle, {
|
|
9
|
+
setError: (value) => {
|
|
10
|
+
error.set(value);
|
|
11
|
+
},
|
|
12
|
+
setPending: (value) => {
|
|
13
|
+
pending.set(value);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return { error, isError, mutate, pending, reset };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { mutator };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readable } from 'svelte/store';
|
|
2
|
-
import { getLunoraClient } from './
|
|
2
|
+
import { getLunoraClient } from './getLunoraClient--bwSz7F6.mjs';
|
|
3
3
|
|
|
4
4
|
const makeSessionId = () => {
|
|
5
5
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createQuerySubscription } from '@lunora/client/query';
|
|
2
2
|
import { readable } from 'svelte/store';
|
|
3
|
-
import { getLunoraClient } from './
|
|
3
|
+
import { getLunoraClient } from './getLunoraClient--bwSz7F6.mjs';
|
|
4
4
|
import { i as isFunctionReference } from './is-function-reference-ycLAcI79.mjs';
|
|
5
5
|
|
|
6
6
|
function query(clientOrFunction, functionOrArguments, argumentsOrOptions, maybeOptions) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createQuerySubscription } from '@lunora/client/query';
|
|
2
2
|
import { writable, readable } from 'svelte/store';
|
|
3
|
-
import { getLunoraClient } from './
|
|
3
|
+
import { getLunoraClient } from './getLunoraClient--bwSz7F6.mjs';
|
|
4
4
|
import { i as isFunctionReference } from './is-function-reference-ycLAcI79.mjs';
|
|
5
5
|
|
|
6
6
|
function subscription(clientOrFunction, functionOrArgs, argsOrOptions, maybeOptions) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/svelte",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.21",
|
|
4
4
|
"description": "Svelte adapter for Lunora — live stores, optimistic mutations, and reactive loaders",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"directory": "packages/svelte"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"dist",
|
|
28
|
+
"./dist",
|
|
29
29
|
"README.md",
|
|
30
30
|
"LICENSE.md",
|
|
31
31
|
"__assets__"
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@lunora/client": "1.0.0-alpha.
|
|
58
|
-
"@lunora/ratelimit": "1.0.0-alpha.
|
|
59
|
-
"@lunora/runtime": "1.0.0-alpha.
|
|
57
|
+
"@lunora/client": "1.0.0-alpha.13",
|
|
58
|
+
"@lunora/ratelimit": "1.0.0-alpha.3",
|
|
59
|
+
"@lunora/runtime": "1.0.0-alpha.12"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"svelte": "^5.0.0"
|
|
File without changes
|