@lunora/solid 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/LICENSE.md +6 -0
- package/README.md +2 -0
- package/__assets__/package-og.svg +1 -1
- package/dist/index.d.mts +72 -3
- package/dist/index.d.ts +72 -3
- package/dist/index.mjs +12 -10
- package/dist/packem_shared/{Authenticated-RMT5Q_eE.mjs → AuthLoading-u5QJoV-J.mjs} +1 -1
- package/dist/packem_shared/{LunoraContext-C9SpKj54.mjs → LunoraContext-C59PzHhN.mjs} +2 -1
- package/dist/packem_shared/{LunoraProvider-B5BJFk3K.mjs → LunoraProvider-CzB3zGhy.mjs} +1 -1
- package/dist/packem_shared/{createConnectionStatus-D8GPatZX.mjs → createConnectionStatus-1poqwqR9.mjs} +1 -1
- package/dist/packem_shared/createFlag-DTGaIdMo.mjs +114 -0
- package/dist/packem_shared/{createInfiniteQuery-DyMvQ2Qy.mjs → createInfiniteQuery-q2r4PSqD.mjs} +1 -1
- package/dist/packem_shared/{createMutationForClient-C7BxzO0y.mjs → createMutation-LkrbhItI.mjs} +1 -1
- package/dist/packem_shared/createMutator-foSnPJPt.mjs +24 -0
- package/dist/packem_shared/{createPresence-DiAak1Jw.mjs → createPresence-DMiDP353.mjs} +1 -1
- package/dist/packem_shared/{createQuery-D8mdHfyQ.mjs → createQuery-BUldvZXj.mjs} +1 -1
- package/dist/packem_shared/{createSubscription-BM2fw8hw.mjs → createSubscription-C_ed4Rov.mjs} +1 -1
- package/dist/packem_shared/{hydratePreloaded-CaT1kDBH.mjs → hydratePreloaded-CWny5-2J.mjs} +1 -1
- package/package.json +5 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LunoraClient, User, ConnectionStatus, FunctionReference, ArgsOf, MutationCallOptions, ReturnOf, Preloaded } from '@lunora/client';
|
|
2
|
-
export type { ArgsOf, FunctionReference, OptimisticUpdate, Preloaded, ReturnOf, Unsubscribe } from '@lunora/client';
|
|
1
|
+
import { LunoraClient, User, ConnectionStatus, FunctionReference, ArgsOf, MutationCallOptions, ReturnOf, MutatorHandle, Preloaded } from '@lunora/client';
|
|
2
|
+
export type { ArgsOf, FunctionReference, MutatorHandle, MutatorTransaction, OptimisticUpdate, Preloaded, ReturnOf, Unsubscribe } from '@lunora/client';
|
|
3
3
|
import { Context, JSX, Accessor } from 'solid-js';
|
|
4
4
|
import { PaginationStatus } from '@lunora/client/pagination';
|
|
5
5
|
import { RateLimitStatus, RateLimitConfig } from '@lunora/ratelimit';
|
|
@@ -62,6 +62,43 @@ declare const Unauthenticated: (props: AuthGateProps) => JSX.Element;
|
|
|
62
62
|
* scope disposes (component unmount). Call inside a component / reactive root.
|
|
63
63
|
*/
|
|
64
64
|
declare const createConnectionStatus: () => Accessor<ConnectionStatus>;
|
|
65
|
+
/** A targeting context merged on top of the app's default (`defineFlags({ identify })`). */
|
|
66
|
+
type FlagContext = Record<string, unknown>;
|
|
67
|
+
/** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
|
|
68
|
+
type FlagValue = boolean | number | string | {
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
} | unknown[] | null;
|
|
71
|
+
/** A plain value or a Solid accessor of it — matching `createQuery`'s reactive-args contract. */
|
|
72
|
+
type MaybeAccessor<T> = Accessor<T> | T;
|
|
73
|
+
/**
|
|
74
|
+
* Subscribe to a single feature flag and return a reactive accessor of its value.
|
|
75
|
+
*
|
|
76
|
+
* The accessor reads `defaultValue` until the first evaluation lands, then the
|
|
77
|
+
* server's resolved value — re-pushed whenever the provider re-evaluates (e.g. a
|
|
78
|
+
* flag is toggled in Cloudflare Flagship). The flag's kind is inferred from
|
|
79
|
+
* `defaultValue`'s runtime type, so `createFlag("dark", false)` reads a boolean
|
|
80
|
+
* and `createFlag("hero", "control")` a string.
|
|
81
|
+
*
|
|
82
|
+
* `key` and `context` may be plain values or accessors; passing an accessor makes
|
|
83
|
+
* the subscription reactive — when it changes the old subscription is torn down
|
|
84
|
+
* (via `onCleanup`) and a fresh one opens. `context` supplies a per-call targeting
|
|
85
|
+
* context merged on top of the app's default `identify` targeting key.
|
|
86
|
+
*
|
|
87
|
+
* Evaluation runs through whatever OpenFeature provider the app wired in
|
|
88
|
+
* `lunora/flags.ts`; the read never throws — a provider error resolves the
|
|
89
|
+
* default (the same fail-open contract as server-side `ctx.flags`).
|
|
90
|
+
*/
|
|
91
|
+
declare const createFlag: <T extends FlagValue>(key: MaybeAccessor<string>, defaultValue: T, context?: MaybeAccessor<FlagContext | undefined>) => Accessor<T>;
|
|
92
|
+
/**
|
|
93
|
+
* Subscribe to several feature flags at once and return a reactive accessor of
|
|
94
|
+
* the resolved record.
|
|
95
|
+
*
|
|
96
|
+
* Pass a record of `key → defaultValue`; each flag's kind is inferred from its
|
|
97
|
+
* default, and the accessor reads the same-shaped record with resolved values
|
|
98
|
+
* (the defaults until each evaluation lands). A single `context` applies to every
|
|
99
|
+
* flag and may be an accessor. This is the batched form of {@link createFlag}.
|
|
100
|
+
*/
|
|
101
|
+
declare const createFlags: <T extends Record<string, FlagValue>>(flags: T, context?: MaybeAccessor<FlagContext | undefined>) => Accessor<T>;
|
|
65
102
|
interface MutationHandle<F extends FunctionReference> {
|
|
66
103
|
/** The latest invocation's resolved value, or `undefined` before the first success. */
|
|
67
104
|
data: Accessor<ReturnOf<F> | undefined>;
|
|
@@ -107,6 +144,38 @@ declare const createMutationForClient: <F extends FunctionReference>(client: Mut
|
|
|
107
144
|
* down, so `mutate` stays durable across reconnects.
|
|
108
145
|
*/
|
|
109
146
|
declare const createMutation: <F extends FunctionReference>(function_: F) => MutationHandle<F>;
|
|
147
|
+
/**
|
|
148
|
+
* The reactive handle returned by {@link createMutator} — the Solid counterpart
|
|
149
|
+
* to `@lunora/react`'s `useMutator`, re-expressed with signals.
|
|
150
|
+
* `error`/`isError`/`pending` are accessors and `mutate` is an awaitable that
|
|
151
|
+
* resolves once the write is persisted (or rejects).
|
|
152
|
+
*/
|
|
153
|
+
interface MutatorHook<TArgs> {
|
|
154
|
+
/** The latest invocation's error, or `undefined`. */
|
|
155
|
+
error: Accessor<Error | undefined>;
|
|
156
|
+
/** `true` when the latest invocation rejected. */
|
|
157
|
+
isError: Accessor<boolean>;
|
|
158
|
+
/** Run the mutator; resolves once the write is persisted, rejects on failure. */
|
|
159
|
+
mutate: (args: TArgs) => Promise<void>;
|
|
160
|
+
/** `true` while ANY invocation from this handle is in flight (ref-counted, so overlapping calls compose). */
|
|
161
|
+
pending: Accessor<boolean>;
|
|
162
|
+
/** Clear the latest `error` back to idle. */
|
|
163
|
+
reset: () => void;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
|
|
167
|
+
* custom-mutator handle from `@lunora/db`'s `bindMutators` — the Solid
|
|
168
|
+
* equivalent of `@lunora/react`'s `useMutator`. The optimistic overlay and
|
|
169
|
+
* server-authoritative push are owned by the bound handle (and TanStack DB's
|
|
170
|
+
* optimistic-transaction layer rebases pending overlays on every sync tick);
|
|
171
|
+
* this primitive only surfaces signal state for the in-flight/error lifecycle.
|
|
172
|
+
* Reads stay on the existing TanStack `useLiveQuery`; no new query primitive is
|
|
173
|
+
* needed.
|
|
174
|
+
*
|
|
175
|
+
* `pending` is ref-counted across overlapping invocations of THIS handle, so it
|
|
176
|
+
* clears only once every concurrent call has settled.
|
|
177
|
+
*/
|
|
178
|
+
declare const createMutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorHook<TArgs>;
|
|
110
179
|
/** The args a paginated query exposes minus the framework-supplied page cursor. */
|
|
111
180
|
type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOf<F>, "paginationOpts">;
|
|
112
181
|
/** The element type of the `page` array a paginated query returns. */
|
|
@@ -336,4 +405,4 @@ interface LunoraProviderProps {
|
|
|
336
405
|
* ```
|
|
337
406
|
*/
|
|
338
407
|
declare const LunoraProvider: (props: LunoraProviderProps) => JSX.Element;
|
|
339
|
-
export { AuthLoading, Authenticated, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreatePaginatedQueryOptions, type CreatePaginatedQueryResult, type CreatePresenceOptions, type CreatePresenceResult, type CreateQueryOptions, type CreateRateLimitOptions, type CreateRateLimitResult, type CreateSubscriptionResult, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider, type LunoraProviderProps, type MutationClient, type MutationHandle, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAuthResult, createAuth, createConnectionStatus, createInfiniteQuery, createMutation, createMutationForClient, createPaginatedQuery, createPresence, createQuery, createRateLimit, createSubscription, hydratePreloaded, useLunora };
|
|
408
|
+
export { AuthLoading, Authenticated, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreatePaginatedQueryOptions, type CreatePaginatedQueryResult, type CreatePresenceOptions, type CreatePresenceResult, type CreateQueryOptions, type CreateRateLimitOptions, type CreateRateLimitResult, type CreateSubscriptionResult, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider, type LunoraProviderProps, type MutationClient, type MutationHandle, type MutatorHook, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAuthResult, createAuth, createConnectionStatus, createFlag, createFlags, createInfiniteQuery, createMutation, createMutationForClient, createMutator, createPaginatedQuery, createPresence, createQuery, createRateLimit, createSubscription, hydratePreloaded, useLunora };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LunoraClient, User, ConnectionStatus, FunctionReference, ArgsOf, MutationCallOptions, ReturnOf, Preloaded } from '@lunora/client';
|
|
2
|
-
export type { ArgsOf, FunctionReference, OptimisticUpdate, Preloaded, ReturnOf, Unsubscribe } from '@lunora/client';
|
|
1
|
+
import { LunoraClient, User, ConnectionStatus, FunctionReference, ArgsOf, MutationCallOptions, ReturnOf, MutatorHandle, Preloaded } from '@lunora/client';
|
|
2
|
+
export type { ArgsOf, FunctionReference, MutatorHandle, MutatorTransaction, OptimisticUpdate, Preloaded, ReturnOf, Unsubscribe } from '@lunora/client';
|
|
3
3
|
import { Context, JSX, Accessor } from 'solid-js';
|
|
4
4
|
import { PaginationStatus } from '@lunora/client/pagination';
|
|
5
5
|
import { RateLimitStatus, RateLimitConfig } from '@lunora/ratelimit';
|
|
@@ -62,6 +62,43 @@ declare const Unauthenticated: (props: AuthGateProps) => JSX.Element;
|
|
|
62
62
|
* scope disposes (component unmount). Call inside a component / reactive root.
|
|
63
63
|
*/
|
|
64
64
|
declare const createConnectionStatus: () => Accessor<ConnectionStatus>;
|
|
65
|
+
/** A targeting context merged on top of the app's default (`defineFlags({ identify })`). */
|
|
66
|
+
type FlagContext = Record<string, unknown>;
|
|
67
|
+
/** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
|
|
68
|
+
type FlagValue = boolean | number | string | {
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
} | unknown[] | null;
|
|
71
|
+
/** A plain value or a Solid accessor of it — matching `createQuery`'s reactive-args contract. */
|
|
72
|
+
type MaybeAccessor<T> = Accessor<T> | T;
|
|
73
|
+
/**
|
|
74
|
+
* Subscribe to a single feature flag and return a reactive accessor of its value.
|
|
75
|
+
*
|
|
76
|
+
* The accessor reads `defaultValue` until the first evaluation lands, then the
|
|
77
|
+
* server's resolved value — re-pushed whenever the provider re-evaluates (e.g. a
|
|
78
|
+
* flag is toggled in Cloudflare Flagship). The flag's kind is inferred from
|
|
79
|
+
* `defaultValue`'s runtime type, so `createFlag("dark", false)` reads a boolean
|
|
80
|
+
* and `createFlag("hero", "control")` a string.
|
|
81
|
+
*
|
|
82
|
+
* `key` and `context` may be plain values or accessors; passing an accessor makes
|
|
83
|
+
* the subscription reactive — when it changes the old subscription is torn down
|
|
84
|
+
* (via `onCleanup`) and a fresh one opens. `context` supplies a per-call targeting
|
|
85
|
+
* context merged on top of the app's default `identify` targeting key.
|
|
86
|
+
*
|
|
87
|
+
* Evaluation runs through whatever OpenFeature provider the app wired in
|
|
88
|
+
* `lunora/flags.ts`; the read never throws — a provider error resolves the
|
|
89
|
+
* default (the same fail-open contract as server-side `ctx.flags`).
|
|
90
|
+
*/
|
|
91
|
+
declare const createFlag: <T extends FlagValue>(key: MaybeAccessor<string>, defaultValue: T, context?: MaybeAccessor<FlagContext | undefined>) => Accessor<T>;
|
|
92
|
+
/**
|
|
93
|
+
* Subscribe to several feature flags at once and return a reactive accessor of
|
|
94
|
+
* the resolved record.
|
|
95
|
+
*
|
|
96
|
+
* Pass a record of `key → defaultValue`; each flag's kind is inferred from its
|
|
97
|
+
* default, and the accessor reads the same-shaped record with resolved values
|
|
98
|
+
* (the defaults until each evaluation lands). A single `context` applies to every
|
|
99
|
+
* flag and may be an accessor. This is the batched form of {@link createFlag}.
|
|
100
|
+
*/
|
|
101
|
+
declare const createFlags: <T extends Record<string, FlagValue>>(flags: T, context?: MaybeAccessor<FlagContext | undefined>) => Accessor<T>;
|
|
65
102
|
interface MutationHandle<F extends FunctionReference> {
|
|
66
103
|
/** The latest invocation's resolved value, or `undefined` before the first success. */
|
|
67
104
|
data: Accessor<ReturnOf<F> | undefined>;
|
|
@@ -107,6 +144,38 @@ declare const createMutationForClient: <F extends FunctionReference>(client: Mut
|
|
|
107
144
|
* down, so `mutate` stays durable across reconnects.
|
|
108
145
|
*/
|
|
109
146
|
declare const createMutation: <F extends FunctionReference>(function_: F) => MutationHandle<F>;
|
|
147
|
+
/**
|
|
148
|
+
* The reactive handle returned by {@link createMutator} — the Solid counterpart
|
|
149
|
+
* to `@lunora/react`'s `useMutator`, re-expressed with signals.
|
|
150
|
+
* `error`/`isError`/`pending` are accessors and `mutate` is an awaitable that
|
|
151
|
+
* resolves once the write is persisted (or rejects).
|
|
152
|
+
*/
|
|
153
|
+
interface MutatorHook<TArgs> {
|
|
154
|
+
/** The latest invocation's error, or `undefined`. */
|
|
155
|
+
error: Accessor<Error | undefined>;
|
|
156
|
+
/** `true` when the latest invocation rejected. */
|
|
157
|
+
isError: Accessor<boolean>;
|
|
158
|
+
/** Run the mutator; resolves once the write is persisted, rejects on failure. */
|
|
159
|
+
mutate: (args: TArgs) => Promise<void>;
|
|
160
|
+
/** `true` while ANY invocation from this handle is in flight (ref-counted, so overlapping calls compose). */
|
|
161
|
+
pending: Accessor<boolean>;
|
|
162
|
+
/** Clear the latest `error` back to idle. */
|
|
163
|
+
reset: () => void;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
|
|
167
|
+
* custom-mutator handle from `@lunora/db`'s `bindMutators` — the Solid
|
|
168
|
+
* equivalent of `@lunora/react`'s `useMutator`. The optimistic overlay and
|
|
169
|
+
* server-authoritative push are owned by the bound handle (and TanStack DB's
|
|
170
|
+
* optimistic-transaction layer rebases pending overlays on every sync tick);
|
|
171
|
+
* this primitive only surfaces signal state for the in-flight/error lifecycle.
|
|
172
|
+
* Reads stay on the existing TanStack `useLiveQuery`; no new query primitive is
|
|
173
|
+
* needed.
|
|
174
|
+
*
|
|
175
|
+
* `pending` is ref-counted across overlapping invocations of THIS handle, so it
|
|
176
|
+
* clears only once every concurrent call has settled.
|
|
177
|
+
*/
|
|
178
|
+
declare const createMutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorHook<TArgs>;
|
|
110
179
|
/** The args a paginated query exposes minus the framework-supplied page cursor. */
|
|
111
180
|
type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOf<F>, "paginationOpts">;
|
|
112
181
|
/** The element type of the `page` array a paginated query returns. */
|
|
@@ -336,4 +405,4 @@ interface LunoraProviderProps {
|
|
|
336
405
|
* ```
|
|
337
406
|
*/
|
|
338
407
|
declare const LunoraProvider: (props: LunoraProviderProps) => JSX.Element;
|
|
339
|
-
export { AuthLoading, Authenticated, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreatePaginatedQueryOptions, type CreatePaginatedQueryResult, type CreatePresenceOptions, type CreatePresenceResult, type CreateQueryOptions, type CreateRateLimitOptions, type CreateRateLimitResult, type CreateSubscriptionResult, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider, type LunoraProviderProps, type MutationClient, type MutationHandle, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAuthResult, createAuth, createConnectionStatus, createInfiniteQuery, createMutation, createMutationForClient, createPaginatedQuery, createPresence, createQuery, createRateLimit, createSubscription, hydratePreloaded, useLunora };
|
|
408
|
+
export { AuthLoading, Authenticated, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreatePaginatedQueryOptions, type CreatePaginatedQueryResult, type CreatePresenceOptions, type CreatePresenceResult, type CreateQueryOptions, type CreateRateLimitOptions, type CreateRateLimitResult, type CreateSubscriptionResult, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider, type LunoraProviderProps, type MutationClient, type MutationHandle, type MutatorHook, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAuthResult, createAuth, createConnectionStatus, createFlag, createFlags, createInfiniteQuery, createMutation, createMutationForClient, createMutator, createPaginatedQuery, createPresence, createQuery, createRateLimit, createSubscription, hydratePreloaded, useLunora };
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
export { LunoraContext, useLunora } from './packem_shared/LunoraContext-
|
|
2
|
-
export { AuthLoading, Authenticated, Unauthenticated, createAuth } from './packem_shared/
|
|
3
|
-
export { default as createConnectionStatus } from './packem_shared/createConnectionStatus-
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
1
|
+
export { LunoraContext, useLunora } from './packem_shared/LunoraContext-C59PzHhN.mjs';
|
|
2
|
+
export { AuthLoading, Authenticated, Unauthenticated, createAuth } from './packem_shared/AuthLoading-u5QJoV-J.mjs';
|
|
3
|
+
export { default as createConnectionStatus } from './packem_shared/createConnectionStatus-1poqwqR9.mjs';
|
|
4
|
+
export { createFlag, createFlags } from './packem_shared/createFlag-DTGaIdMo.mjs';
|
|
5
|
+
export { createMutation, createMutationForClient } from './packem_shared/createMutation-LkrbhItI.mjs';
|
|
6
|
+
export { createMutator } from './packem_shared/createMutator-foSnPJPt.mjs';
|
|
7
|
+
export { createInfiniteQuery, createPaginatedQuery } from './packem_shared/createInfiniteQuery-q2r4PSqD.mjs';
|
|
8
|
+
export { createPresence } from './packem_shared/createPresence-DMiDP353.mjs';
|
|
9
|
+
export { createQuery } from './packem_shared/createQuery-BUldvZXj.mjs';
|
|
8
10
|
export { createRateLimit } from './packem_shared/createRateLimit-BA2f8XyF.mjs';
|
|
9
|
-
export { createSubscription } from './packem_shared/createSubscription-
|
|
10
|
-
export { default as hydratePreloaded } from './packem_shared/hydratePreloaded-
|
|
11
|
-
export { LunoraProvider } from './packem_shared/LunoraProvider-
|
|
11
|
+
export { createSubscription } from './packem_shared/createSubscription-C_ed4Rov.mjs';
|
|
12
|
+
export { default as hydratePreloaded } from './packem_shared/hydratePreloaded-CWny5-2J.mjs';
|
|
13
|
+
export { LunoraProvider } from './packem_shared/LunoraProvider-CzB3zGhy.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createComponent, memo } from 'solid-js/web';
|
|
2
2
|
import { getIdentityStore } from '@lunora/client/auth';
|
|
3
3
|
import { Show, createSignal, onCleanup } from 'solid-js';
|
|
4
|
-
import { useLunora } from './LunoraContext-
|
|
4
|
+
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
5
5
|
|
|
6
6
|
const createAuth = () => {
|
|
7
7
|
const client = useLunora();
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { LunoraError } from '@lunora/errors';
|
|
1
2
|
import { createContext, useContext } from 'solid-js';
|
|
2
3
|
|
|
3
4
|
const LunoraContext = createContext();
|
|
4
5
|
const useLunora = () => {
|
|
5
6
|
const client = useContext(LunoraContext);
|
|
6
7
|
if (!client) {
|
|
7
|
-
throw new
|
|
8
|
+
throw new LunoraError("INTERNAL", "useLunora must be used inside <LunoraProvider />");
|
|
8
9
|
}
|
|
9
10
|
return client;
|
|
10
11
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createComponent } from 'solid-js/web';
|
|
2
|
-
import { LunoraContext } from './LunoraContext-
|
|
2
|
+
import { LunoraContext } from './LunoraContext-C59PzHhN.mjs';
|
|
3
3
|
|
|
4
4
|
const LunoraProvider = (props) => (
|
|
5
5
|
// `props.client` is read lazily inside the JSX so Solid tracks it: swapping
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { createSignal, createEffect, on, onCleanup } from 'solid-js';
|
|
2
|
+
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
3
|
+
|
|
4
|
+
const compareKeys = (a, b) => {
|
|
5
|
+
if (a < b) {
|
|
6
|
+
return -1;
|
|
7
|
+
}
|
|
8
|
+
return a > b ? 1 : 0;
|
|
9
|
+
};
|
|
10
|
+
const stableStringify = (value) => {
|
|
11
|
+
if (value === void 0) {
|
|
12
|
+
return "null";
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === "bigint") {
|
|
15
|
+
throw new TypeError("stableStringify: cannot use a bigint in a cache key (query/subscription/shape args) — pass it as a string");
|
|
16
|
+
}
|
|
17
|
+
if (value === null || typeof value !== "object") {
|
|
18
|
+
return JSON.stringify(value);
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(value)) {
|
|
21
|
+
return `[${value.map((item) => stableStringify(item)).join(",")}]`;
|
|
22
|
+
}
|
|
23
|
+
const proto = Object.getPrototypeOf(value);
|
|
24
|
+
if (proto !== null && proto !== Object.prototype) {
|
|
25
|
+
const name = value.constructor?.name ?? "value";
|
|
26
|
+
throw new TypeError(`stableStringify: cannot use a ${name} in a cache key (query/subscription/shape args) — only plain objects, arrays, and JSON primitives are supported`);
|
|
27
|
+
}
|
|
28
|
+
const record = value;
|
|
29
|
+
const keys = Object.keys(record).toSorted(compareKeys);
|
|
30
|
+
const parts = [];
|
|
31
|
+
for (const key of keys) {
|
|
32
|
+
const raw = record[key];
|
|
33
|
+
if (raw === void 0) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
parts.push(`${JSON.stringify(key)}:${stableStringify(raw)}`);
|
|
37
|
+
}
|
|
38
|
+
return `{${parts.join(",")}}`;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
|
|
42
|
+
const flagKind = (value) => {
|
|
43
|
+
const kind = typeof value;
|
|
44
|
+
if (kind === "boolean" || kind === "number" || kind === "string") {
|
|
45
|
+
return kind;
|
|
46
|
+
}
|
|
47
|
+
return "object";
|
|
48
|
+
};
|
|
49
|
+
const flagsReference = {
|
|
50
|
+
__lunoraRef: FLAGS_EVAL_PATH
|
|
51
|
+
};
|
|
52
|
+
const resolveMaybe = (value) => typeof value === "function" ? value() : value;
|
|
53
|
+
const serializeContext = (context) => context === void 0 ? "" : stableStringify(context);
|
|
54
|
+
const createFlag = (key, defaultValue, context) => {
|
|
55
|
+
const client = useLunora();
|
|
56
|
+
const type = flagKind(defaultValue);
|
|
57
|
+
const [value, setValue] = createSignal(defaultValue);
|
|
58
|
+
createEffect(on(() => `${resolveMaybe(key)} ${serializeContext(resolveMaybe(context))}`, () => {
|
|
59
|
+
const currentKey = resolveMaybe(key);
|
|
60
|
+
const currentContext = resolveMaybe(context);
|
|
61
|
+
setValue(() => defaultValue);
|
|
62
|
+
let unsubscribe;
|
|
63
|
+
try {
|
|
64
|
+
unsubscribe = client.subscribe(flagsReference, {
|
|
65
|
+
context: currentContext,
|
|
66
|
+
default: defaultValue,
|
|
67
|
+
key: currentKey,
|
|
68
|
+
type
|
|
69
|
+
}, (next) => {
|
|
70
|
+
setValue(() => next);
|
|
71
|
+
});
|
|
72
|
+
} catch {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
onCleanup(unsubscribe);
|
|
76
|
+
}));
|
|
77
|
+
return value;
|
|
78
|
+
};
|
|
79
|
+
const createFlags = (flags, context) => {
|
|
80
|
+
const client = useLunora();
|
|
81
|
+
const [values, setValues] = createSignal(flags);
|
|
82
|
+
const spec = stableStringify(flags);
|
|
83
|
+
createEffect(on(() => `${spec} ${serializeContext(resolveMaybe(context))}`, () => {
|
|
84
|
+
const currentContext = resolveMaybe(context);
|
|
85
|
+
setValues(() => flags);
|
|
86
|
+
const unsubscribes = [];
|
|
87
|
+
for (const [key, defaultValue] of Object.entries(flags)) {
|
|
88
|
+
try {
|
|
89
|
+
unsubscribes.push(client.subscribe(flagsReference, {
|
|
90
|
+
context: currentContext,
|
|
91
|
+
default: defaultValue,
|
|
92
|
+
key,
|
|
93
|
+
type: flagKind(defaultValue)
|
|
94
|
+
}, (next) => {
|
|
95
|
+
setValues((previous) => {
|
|
96
|
+
return {
|
|
97
|
+
...previous,
|
|
98
|
+
[key]: next
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
}));
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
onCleanup(() => {
|
|
106
|
+
for (const unsubscribe of unsubscribes) {
|
|
107
|
+
unsubscribe();
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}));
|
|
111
|
+
return values;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export { createFlag, createFlags };
|
package/dist/packem_shared/{createInfiniteQuery-DyMvQ2Qy.mjs → createInfiniteQuery-q2r4PSqD.mjs}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { initialPages, derivePaginationStatus, rebalance, applyLoadMore } from '@lunora/client/pagination';
|
|
2
2
|
import { createMemo, createSignal, createEffect, on, onCleanup } from 'solid-js';
|
|
3
|
-
import { useLunora } from './LunoraContext-
|
|
3
|
+
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
4
4
|
|
|
5
5
|
const buildPageArgs = (page, baseArgs) => {
|
|
6
6
|
return {
|
package/dist/packem_shared/{createMutationForClient-C7BxzO0y.mjs → createMutation-LkrbhItI.mjs}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createMutationRunner } from '@lunora/client';
|
|
2
2
|
import { createSignal } from 'solid-js';
|
|
3
|
-
import { useLunora } from './LunoraContext-
|
|
3
|
+
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
4
4
|
|
|
5
5
|
const createMutationForClient = (client, function_) => {
|
|
6
6
|
const [data, setData] = createSignal(void 0);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createMutatorRunner } from '@lunora/client';
|
|
2
|
+
import { createSignal } from 'solid-js';
|
|
3
|
+
|
|
4
|
+
const createMutator = (handle) => {
|
|
5
|
+
const [error, setError] = createSignal(void 0);
|
|
6
|
+
const [pending, setPending] = createSignal(false);
|
|
7
|
+
const {
|
|
8
|
+
mutate,
|
|
9
|
+
reset
|
|
10
|
+
} = createMutatorRunner(handle, {
|
|
11
|
+
setError,
|
|
12
|
+
setPending
|
|
13
|
+
});
|
|
14
|
+
const isError = () => error() !== void 0;
|
|
15
|
+
return {
|
|
16
|
+
error,
|
|
17
|
+
isError,
|
|
18
|
+
mutate,
|
|
19
|
+
pending,
|
|
20
|
+
reset
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { createMutator };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createSignal, onMount, onCleanup } from 'solid-js';
|
|
2
|
-
import { useLunora } from './LunoraContext-
|
|
2
|
+
import { useLunora } from './LunoraContext-C59PzHhN.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 { createSignal, createEffect, on, onCleanup } from 'solid-js';
|
|
3
|
-
import { useLunora } from './LunoraContext-
|
|
3
|
+
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
4
4
|
|
|
5
5
|
const createQuery = (function_, args, options = {}) => {
|
|
6
6
|
const client = useLunora();
|
package/dist/packem_shared/{createSubscription-BM2fw8hw.mjs → createSubscription-C_ed4Rov.mjs}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createQuerySubscription } from '@lunora/client/query';
|
|
2
2
|
import { createSignal, createEffect, on, onCleanup } from 'solid-js';
|
|
3
|
-
import { useLunora } from './LunoraContext-
|
|
3
|
+
import { useLunora } from './LunoraContext-C59PzHhN.mjs';
|
|
4
4
|
|
|
5
5
|
const createSubscription = (function_, args, options = {}) => {
|
|
6
6
|
const client = useLunora();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/solid",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.21",
|
|
4
4
|
"description": "SolidJS adapter for Lunora — live queries, optimistic mutations, and reactive loaders",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"directory": "packages/solid"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"dist",
|
|
28
|
+
"./dist",
|
|
29
29
|
"README.md",
|
|
30
30
|
"LICENSE.md",
|
|
31
31
|
"__assets__"
|
|
@@ -50,8 +50,9 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@lunora/client": "1.0.0-alpha.
|
|
54
|
-
"@lunora/
|
|
53
|
+
"@lunora/client": "1.0.0-alpha.19",
|
|
54
|
+
"@lunora/errors": "1.0.0-alpha.2",
|
|
55
|
+
"@lunora/ratelimit": "1.0.0-alpha.5"
|
|
55
56
|
},
|
|
56
57
|
"peerDependencies": {
|
|
57
58
|
"solid-js": "^1.9.0"
|