@effectify/solid-query 0.4.6 → 0.5.0
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 +8 -14
- package/dist/package.json +7 -7
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.js +3 -3
- package/dist/src/lib/internal/make-use-effect-mutation.d.ts +2 -2
- package/dist/src/lib/internal/make-use-effect-mutation.js +1 -1
- package/dist/src/lib/internal/make-use-effect-query.d.ts +2 -2
- package/dist/src/lib/internal/make-use-effect-query.js +4 -4
- package/dist/src/lib/internal/make-use-rx-subsciption-ref.d.ts +5 -5
- package/dist/src/lib/internal/make-use-rx-subsciption-ref.js +9 -7
- package/dist/src/lib/internal/make-use-rx-subscribe.d.ts +4 -4
- package/dist/src/lib/internal/make-use-rx-subscribe.js +6 -7
- package/dist/src/lib/internal/query-data-helpers.d.ts +1 -1
- package/dist/src/lib/internal/query-data-helpers.js +2 -2
- package/dist/src/lib/tanstack-query-effect.d.ts +5 -5
- package/dist/src/lib/tanstack-query-effect.jsx +11 -11
- package/dist/src/lib/types.d.ts +8 -8
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -21,12 +21,12 @@ bun add @effectify/solid-query
|
|
|
21
21
|
## Basic Usage
|
|
22
22
|
|
|
23
23
|
```tsx
|
|
24
|
-
import * as Layer from
|
|
25
|
-
import * as Effect from
|
|
26
|
-
import { tanstackQueryEffect } from
|
|
24
|
+
import * as Layer from "effect/Layer"
|
|
25
|
+
import * as Effect from "effect/Effect"
|
|
26
|
+
import { tanstackQueryEffect } from "@effectify/solid-query"
|
|
27
27
|
|
|
28
28
|
// Create an Effect layer
|
|
29
|
-
const AppLayer = Layer.succeed(
|
|
29
|
+
const AppLayer = Layer.succeed("AppConfig", { apiUrl: "https://api.example.com" })
|
|
30
30
|
|
|
31
31
|
// Initialize the TanStack Query integration
|
|
32
32
|
const {
|
|
@@ -50,21 +50,15 @@ function App() {
|
|
|
50
50
|
// Use in components
|
|
51
51
|
function YourComponent() {
|
|
52
52
|
const query = useEffectQuery({
|
|
53
|
-
queryKey: [
|
|
54
|
-
queryFn: () => Effect.succeed([
|
|
53
|
+
queryKey: ["data"],
|
|
54
|
+
queryFn: () => Effect.succeed(["item1", "item2"]),
|
|
55
55
|
})
|
|
56
56
|
|
|
57
57
|
return (
|
|
58
58
|
<div>
|
|
59
|
-
{query.isPending ? (
|
|
60
|
-
<p>Loading...</p>
|
|
61
|
-
) : query.isError ? (
|
|
62
|
-
<p>Error: {query.error.message}</p>
|
|
63
|
-
) : (
|
|
59
|
+
{query.isPending ? <p>Loading...</p> : query.isError ? <p>Error: {query.error.message}</p> : (
|
|
64
60
|
<ul>
|
|
65
|
-
{query.data.map((item) =>
|
|
66
|
-
<li>{item}</li>
|
|
67
|
-
))}
|
|
61
|
+
{query.data.map((item) => <li>{item}</li>)}
|
|
68
62
|
</ul>
|
|
69
63
|
)}
|
|
70
64
|
</div>
|
package/dist/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectify/solid-query",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Integration of Effect with TanStack Query for Solid.js",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.js",
|
|
7
|
-
"module": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
6
|
+
"main": "./dist/src/index.js",
|
|
7
|
+
"module": "./dist/src/index.js",
|
|
8
|
+
"types": "./dist/src/index.d.ts",
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"@effectify/source": "./src/index.ts",
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"import": "./dist/index.js",
|
|
17
|
-
"default": "./dist/index.js"
|
|
15
|
+
"types": "./dist/src/index.d.ts",
|
|
16
|
+
"import": "./dist/src/index.js",
|
|
17
|
+
"default": "./dist/src/index.js"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./lib/internal/query-data-helpers.js";
|
|
2
|
+
export * from "./lib/tanstack-query-effect.jsx";
|
|
3
|
+
export * from "./lib/types.js";
|
package/dist/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./lib/internal/query-data-helpers.js";
|
|
2
|
+
export * from "./lib/tanstack-query-effect.jsx";
|
|
3
|
+
export * from "./lib/types.js";
|
|
4
4
|
// Testing release workflow with changelog generation
|
|
5
5
|
// This should only affect solid-query package
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type UseMutationResult } from
|
|
2
|
-
import type { EffectfulError, EffectfulMutationOptions, Runner } from
|
|
1
|
+
import { type UseMutationResult } from "@tanstack/solid-query";
|
|
2
|
+
import type { EffectfulError, EffectfulMutationOptions, Runner } from "../types.js";
|
|
3
3
|
export declare const makeUseEffectMutation: <R>(createRunner: Runner<R>) => <TData, TError extends EffectfulError, TVariables>(options: EffectfulMutationOptions<TData, TError, TVariables, R>) => UseMutationResult<TData, Error, TVariables>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type UseQueryResult } from
|
|
2
|
-
import type { EffectfulError, EffectfulQueryOptions, QueryKey, Runner } from
|
|
1
|
+
import { type UseQueryResult } from "@tanstack/solid-query";
|
|
2
|
+
import type { EffectfulError, EffectfulQueryOptions, QueryKey, Runner } from "../types.js";
|
|
3
3
|
export declare const makeUseEffectQuery: <R>(createRunner: Runner<R>) => <TData, TError extends EffectfulError, TQueryKey extends QueryKey = QueryKey>({ gcTime, staleTime, ...options }: EffectfulQueryOptions<TData, TError, R, TQueryKey>) => UseQueryResult<TData, Error>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { skipToken } from
|
|
2
|
-
import { useQuery } from
|
|
3
|
-
import * as Duration from
|
|
4
|
-
import { createMemo } from
|
|
1
|
+
import { skipToken } from "@tanstack/query-core";
|
|
2
|
+
import { useQuery } from "@tanstack/solid-query";
|
|
3
|
+
import * as Duration from "effect/Duration";
|
|
4
|
+
import { createMemo } from "solid-js";
|
|
5
5
|
export const makeUseEffectQuery = (createRunner) => ({ gcTime, staleTime, ...options }) => {
|
|
6
6
|
const effectRunner = createRunner();
|
|
7
7
|
const [spanName] = options.queryKey;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as Effect from
|
|
2
|
-
import type * as ManagedRuntime from
|
|
3
|
-
import * as SubscriptionRef from
|
|
4
|
-
import { type Context } from
|
|
5
|
-
import type { Subscribable, SubscriptionOptions } from
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import type * as ManagedRuntime from "effect/ManagedRuntime";
|
|
3
|
+
import * as SubscriptionRef from "effect/SubscriptionRef";
|
|
4
|
+
import { type Context } from "solid-js";
|
|
5
|
+
import type { Subscribable, SubscriptionOptions } from "../types.js";
|
|
6
6
|
export declare const makeUseRxSubscriptionRef: <R, E>(RuntimeContext: Context<ManagedRuntime.ManagedRuntime<R, E> | null>) => <A, E2>(subscribable: Subscribable<A, E2> | Effect.Effect<Subscribable<A, E2>, never, R> | Effect.Effect<SubscriptionRef.SubscriptionRef<A>, never, R>, onNext: (value: A) => void, opts?: SubscriptionOptions) => A;
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import * as Effect from
|
|
2
|
-
import * as Fiber from
|
|
3
|
-
import * as Stream from
|
|
4
|
-
import * as SubscriptionRef from
|
|
5
|
-
import { createEffect, createSignal, onCleanup, useContext } from
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Fiber from "effect/Fiber";
|
|
3
|
+
import * as Stream from "effect/Stream";
|
|
4
|
+
import * as SubscriptionRef from "effect/SubscriptionRef";
|
|
5
|
+
import { createEffect, createSignal, onCleanup, useContext } from "solid-js";
|
|
6
6
|
export const makeUseRxSubscriptionRef = (RuntimeContext) => (subscribable, onNext, opts) => {
|
|
7
7
|
const options = {
|
|
8
8
|
skipInitial: opts?.skipInitial ?? true,
|
|
9
9
|
};
|
|
10
10
|
const runtime = useContext(RuntimeContext);
|
|
11
11
|
if (!runtime) {
|
|
12
|
-
throw new Error(
|
|
12
|
+
throw new Error("Runtime context not found. Make sure to wrap your app with RuntimeProvider");
|
|
13
13
|
}
|
|
14
14
|
const setInitialValue = () => {
|
|
15
15
|
const initialValue = Effect.gen(function* () {
|
|
16
16
|
const resolved = Effect.isEffect(subscribable) ? yield* subscribable : subscribable;
|
|
17
|
-
const resolvedValue = SubscriptionRef.SubscriptionRefTypeId in resolved
|
|
17
|
+
const resolvedValue = SubscriptionRef.SubscriptionRefTypeId in resolved
|
|
18
|
+
? yield* SubscriptionRef.get(resolved)
|
|
19
|
+
: resolved.get();
|
|
18
20
|
if (!options?.skipInitial) {
|
|
19
21
|
onNext(resolvedValue);
|
|
20
22
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as Effect from
|
|
2
|
-
import type * as ManagedRuntime from
|
|
3
|
-
import * as Stream from
|
|
4
|
-
import { type Context } from
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import type * as ManagedRuntime from "effect/ManagedRuntime";
|
|
3
|
+
import * as Stream from "effect/Stream";
|
|
4
|
+
import { type Context } from "solid-js";
|
|
5
5
|
export declare const makeUseRxSubscribe: <R, E>(RuntimeContext: Context<ManagedRuntime.ManagedRuntime<R, E> | null>) => <E2, A>(stream: Stream.Stream<A, E2, R> | Effect.Effect<Stream.Stream<A, E2, R>, E2, R>, initialValue: A, onNext: (value: A) => void, onError?: (error: E2) => void) => import("solid-js").Accessor<A | undefined>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as Effect from
|
|
2
|
-
import * as Exit from
|
|
3
|
-
import * as Fiber from
|
|
4
|
-
import * as Stream from
|
|
5
|
-
import { createSignal, onCleanup, useContext } from
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Exit from "effect/Exit";
|
|
3
|
+
import * as Fiber from "effect/Fiber";
|
|
4
|
+
import * as Stream from "effect/Stream";
|
|
5
|
+
import { createSignal, onCleanup, useContext } from "solid-js";
|
|
6
6
|
export const makeUseRxSubscribe = (RuntimeContext) => {
|
|
7
7
|
return (stream, initialValue, onNext, onError) => {
|
|
8
8
|
const runtime = useContext(RuntimeContext);
|
|
9
9
|
if (!runtime) {
|
|
10
|
-
throw new Error(
|
|
10
|
+
throw new Error("Runtime context not found. Make sure to wrap your app with RuntimeProvider");
|
|
11
11
|
}
|
|
12
12
|
const [value, setValue] = createSignal(initialValue);
|
|
13
13
|
const [fiberRef, setFiberRef] = createSignal(null);
|
|
@@ -28,7 +28,6 @@ export const makeUseRxSubscribe = (RuntimeContext) => {
|
|
|
28
28
|
});
|
|
29
29
|
onCleanup(() => {
|
|
30
30
|
if (fiberRef() !== null) {
|
|
31
|
-
// biome-ignore lint/style/noNonNullAssertion: <testing>
|
|
32
31
|
runtime.runCallback(Fiber.interrupt(fiberRef()));
|
|
33
32
|
}
|
|
34
33
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Simple deep clone function to replace mutative
|
|
2
2
|
function deepClone(obj) {
|
|
3
|
-
if (obj === null || typeof obj !==
|
|
3
|
+
if (obj === null || typeof obj !== "object") {
|
|
4
4
|
return obj;
|
|
5
5
|
}
|
|
6
6
|
if (obj instanceof Date) {
|
|
@@ -9,7 +9,7 @@ function deepClone(obj) {
|
|
|
9
9
|
if (Array.isArray(obj)) {
|
|
10
10
|
return obj.map((item) => deepClone(item));
|
|
11
11
|
}
|
|
12
|
-
if (typeof obj ===
|
|
12
|
+
if (typeof obj === "object") {
|
|
13
13
|
const cloned = {};
|
|
14
14
|
for (const key in obj) {
|
|
15
15
|
if (Object.hasOwn(obj, key)) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type QueryClient } from
|
|
2
|
-
import * as Effect from
|
|
3
|
-
import type * as Layer from
|
|
4
|
-
import * as ManagedRuntime from
|
|
5
|
-
import { type Component, type JSX } from
|
|
1
|
+
import { type QueryClient } from "@tanstack/solid-query";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import type * as Layer from "effect/Layer";
|
|
4
|
+
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
5
|
+
import { type Component, type JSX } from "solid-js";
|
|
6
6
|
export declare const tanstackQueryEffect: <R, E>({ layer, queryClient, }: {
|
|
7
7
|
layer: Layer.Layer<R, E, never>;
|
|
8
8
|
queryClient: QueryClient;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { QueryClientProvider } from
|
|
2
|
-
import * as Effect from
|
|
3
|
-
import * as ManagedRuntime from
|
|
4
|
-
import { createContext, createMemo, onCleanup, useContext } from
|
|
5
|
-
import { makeUseEffectMutation } from
|
|
6
|
-
import { makeUseEffectQuery } from
|
|
7
|
-
import { makeUseRxSubscriptionRef } from
|
|
8
|
-
import { makeUseRxSubscribe } from
|
|
9
|
-
import { makeCreateQueryDataHelpers } from
|
|
1
|
+
import { QueryClientProvider } from "@tanstack/solid-query";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
4
|
+
import { createContext, createMemo, onCleanup, useContext } from "solid-js";
|
|
5
|
+
import { makeUseEffectMutation } from "./internal/make-use-effect-mutation.js";
|
|
6
|
+
import { makeUseEffectQuery } from "./internal/make-use-effect-query.js";
|
|
7
|
+
import { makeUseRxSubscriptionRef } from "./internal/make-use-rx-subsciption-ref.js";
|
|
8
|
+
import { makeUseRxSubscribe } from "./internal/make-use-rx-subscribe.js";
|
|
9
|
+
import { makeCreateQueryDataHelpers } from "./internal/query-data-helpers.js";
|
|
10
10
|
export const tanstackQueryEffect = ({ layer, queryClient, }) => {
|
|
11
11
|
const RuntimeContext = createContext(null);
|
|
12
12
|
const useRunner = () => {
|
|
13
13
|
const runtime = useContext(RuntimeContext);
|
|
14
14
|
if (!runtime) {
|
|
15
|
-
throw new Error(
|
|
15
|
+
throw new Error("Runtime context not found. Make sure to wrap your app with RuntimeProvider");
|
|
16
16
|
}
|
|
17
17
|
return createMemo(() => (span) => (effect) => effect.pipe(Effect.withSpan(span), Effect.tapErrorCause(Effect.logError), runtime.runPromise));
|
|
18
18
|
};
|
|
@@ -28,7 +28,7 @@ export const tanstackQueryEffect = ({ layer, queryClient, }) => {
|
|
|
28
28
|
const useRuntime = () => {
|
|
29
29
|
const runtime = useContext(RuntimeContext);
|
|
30
30
|
if (!runtime) {
|
|
31
|
-
throw new Error(
|
|
31
|
+
throw new Error("Runtime context not found. Make sure to wrap your app with RuntimeProvider");
|
|
32
32
|
}
|
|
33
33
|
return runtime;
|
|
34
34
|
};
|
package/dist/src/lib/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { QueryFunctionContext, skipToken } from
|
|
2
|
-
import type { UseMutationOptions, UseQueryOptions } from
|
|
3
|
-
import type { DurationInput } from
|
|
4
|
-
import type * as Effect from
|
|
5
|
-
import type * as Stream from
|
|
6
|
-
import type { Accessor } from
|
|
1
|
+
import type { QueryFunctionContext, skipToken } from "@tanstack/query-core";
|
|
2
|
+
import type { UseMutationOptions, UseQueryOptions } from "@tanstack/solid-query";
|
|
3
|
+
import type { DurationInput } from "effect/Duration";
|
|
4
|
+
import type * as Effect from "effect/Effect";
|
|
5
|
+
import type * as Stream from "effect/Stream";
|
|
6
|
+
import type { Accessor } from "solid-js";
|
|
7
7
|
export type QueryKey = readonly [string, Record<string, unknown>?];
|
|
8
8
|
export type EffectfulError = {
|
|
9
9
|
_tag: string;
|
|
@@ -11,12 +11,12 @@ export type EffectfulError = {
|
|
|
11
11
|
export type Runner<R> = () => Accessor<(<A, E>(span: string) => (effect: Effect.Effect<A, E, R>) => Promise<A>)>;
|
|
12
12
|
export type EffectfulMutationOptions<TData, TError extends EffectfulError, TVariables, R> = Omit<UseMutationOptions<TData, Error, TVariables>, // Actualizado a UseMutationOptions
|
|
13
13
|
// Actualizado a UseMutationOptions
|
|
14
|
-
|
|
14
|
+
"mutationFn" | "onSuccess" | "onError" | "onSettled" | "onMutate" | "retry" | "retryDelay"> & {
|
|
15
15
|
mutationKey: QueryKey;
|
|
16
16
|
mutationFn: (variables: TVariables) => Effect.Effect<TData, TError, R>;
|
|
17
17
|
};
|
|
18
18
|
export type EffectfulQueryFunction<TData, TError, TQueryKey extends QueryKey = QueryKey, R = never, TPageParam = never> = (context: QueryFunctionContext<TQueryKey, TPageParam>) => Effect.Effect<TData, TError, R>;
|
|
19
|
-
export type EffectfulQueryOptions<TData, TError, R, TQueryKey extends QueryKey = QueryKey, TPageParam = never> = Omit<UseQueryOptions<TData, Error, TData, TQueryKey>,
|
|
19
|
+
export type EffectfulQueryOptions<TData, TError, R, TQueryKey extends QueryKey = QueryKey, TPageParam = never> = Omit<UseQueryOptions<TData, Error, TData, TQueryKey>, "queryKey" | "queryFn" | "retry" | "retryDelay" | "staleTime" | "gcTime"> & {
|
|
20
20
|
queryKey: TQueryKey;
|
|
21
21
|
queryFn: EffectfulQueryFunction<TData, TError, TQueryKey, R, TPageParam> | typeof skipToken;
|
|
22
22
|
staleTime?: DurationInput;
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectify/solid-query",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Integration of Effect with TanStack Query for Solid.js",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.js",
|
|
7
|
-
"module": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
6
|
+
"main": "./dist/src/index.js",
|
|
7
|
+
"module": "./dist/src/index.js",
|
|
8
|
+
"types": "./dist/src/index.d.ts",
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"@effectify/source": "./src/index.ts",
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"import": "./dist/index.js",
|
|
17
|
-
"default": "./dist/index.js"
|
|
15
|
+
"types": "./dist/src/index.d.ts",
|
|
16
|
+
"import": "./dist/src/index.js",
|
|
17
|
+
"default": "./dist/src/index.js"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"tslib": "2.8.1",
|
|
26
26
|
"@tanstack/solid-query": "5.90.13",
|
|
27
27
|
"@tanstack/query-core": "5.90.10",
|
|
28
|
-
"effect": "3.19.
|
|
28
|
+
"effect": "3.19.15",
|
|
29
29
|
"solid-js": "1.9.10"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|