@lunora/svelte 1.0.0-alpha.10 → 1.0.0-alpha.12

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/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';
@@ -160,6 +160,37 @@ interface MutationHandle<F extends FunctionReference> {
160
160
  */
161
161
  declare function mutation<F extends FunctionReference>(function_: F): MutationHandle<F>;
162
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>;
163
194
  /** The args a paginated query exposes minus the framework-supplied page cursor. */
164
195
  type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOf<F>, "paginationOpts">;
165
196
  /** The element type of the `page` array a paginated query returns. */
@@ -371,4 +402,4 @@ interface SubscriptionHandle<T> {
371
402
  */
372
403
  declare function subscription<F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip", options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
373
404
  declare function subscription<F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F> | "skip", options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
374
- export { type AuthStore, type ConnectionStatusStore, type FlagContext, type FlagValue, 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, flag, flags, 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';
@@ -160,6 +160,37 @@ interface MutationHandle<F extends FunctionReference> {
160
160
  */
161
161
  declare function mutation<F extends FunctionReference>(function_: F): MutationHandle<F>;
162
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>;
163
194
  /** The args a paginated query exposes minus the framework-supplied page cursor. */
164
195
  type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOf<F>, "paginationOpts">;
165
196
  /** The element type of the `page` array a paginated query returns. */
@@ -371,4 +402,4 @@ interface SubscriptionHandle<T> {
371
402
  */
372
403
  declare function subscription<F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip", options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
373
404
  declare function subscription<F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F> | "skip", options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
374
- export { type AuthStore, type ConnectionStatusStore, type FlagContext, type FlagValue, 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, flag, flags, 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
@@ -4,6 +4,7 @@ export { getLunoraClient, setLunoraClient } from './packem_shared/getLunoraClien
4
4
  export { flag, flags } from './packem_shared/flag-19nEeKPT.mjs';
5
5
  export { hydratePreloaded } from './packem_shared/hydratePreloaded-D5rUJdXy.mjs';
6
6
  export { mutation } from './packem_shared/mutation-CnDkAaLH.mjs';
7
+ export { mutator } from './packem_shared/mutator-B5LchgMS.mjs';
7
8
  export { infiniteQuery, paginatedQuery } from './packem_shared/infiniteQuery-jPMQw8Vz.mjs';
8
9
  export { presence } from './packem_shared/presence-BQWixJ2T.mjs';
9
10
  export { query } from './packem_shared/query-D8Pct9Qe.mjs';
@@ -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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/svelte",
3
- "version": "1.0.0-alpha.10",
3
+ "version": "1.0.0-alpha.12",
4
4
  "description": "Svelte adapter for Lunora — live stores, optimistic mutations, and reactive loaders",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -54,9 +54,9 @@
54
54
  "access": "public"
55
55
  },
56
56
  "dependencies": {
57
- "@lunora/client": "1.0.0-alpha.4",
57
+ "@lunora/client": "1.0.0-alpha.6",
58
58
  "@lunora/ratelimit": "1.0.0-alpha.3",
59
- "@lunora/runtime": "1.0.0-alpha.7"
59
+ "@lunora/runtime": "1.0.0-alpha.8"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "svelte": "^5.0.0"