saga-toolkit 2.1.1 → 2.1.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.
Files changed (2) hide show
  1. package/index.d.ts +51 -48
  2. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -1,72 +1,75 @@
1
- // generated with chatGPT
2
-
3
- import { ThunkAction } from '@reduxjs/toolkit'
1
+ import { createAsyncThunk, ThunkAction, SerializedError, Action } from '@reduxjs/toolkit';
2
+ import { ForkEffect, PutEffect, TakeEffect, Saga, CallEffect, ForkEffectDescriptor } from '@redux-saga/core/effects';
3
+ import { Deferred } from '@redux-saga/deferred';
4
4
 
5
5
  declare module 'saga-toolkit' {
6
- import { Dispatch } from 'redux'
7
- import { SagaIterator } from 'redux-saga'
8
- import { AsyncThunkFulfilledActionCreator, AsyncThunkConfig } from '@reduxjs/toolkit/src/createAsyncThunk'
9
-
10
- type AsyncSagaPayloadCreator<Returned, ThunkArg = void> = (
11
- arg: ThunkArg,
12
- requestId: string
13
- ) => Promise<Returned>
14
-
15
- type AsyncSagaActionCreator<
16
- Returned,
17
- ThunkArg,
18
- ThunkApiConfig extends AsyncThunkConfig = {}
19
- > = (
20
- arg: ThunkArg
21
- ) => ThunkAction<
22
- Promise<Returned>,
23
- ReturnType<Dispatch>,
6
+ type SagaAction<Arg, ReturnType> = ThunkAction<
7
+ Promise<ReturnType<Arg>>,
24
8
  unknown,
25
- ReturnType<
26
- AsyncThunkFulfilledActionCreator<Returned, ThunkArg, ThunkApiConfig>
27
- >
28
- >
9
+ { requestId: string },
10
+ Action<string>
11
+ > & {
12
+ type: string;
13
+ requestId: string;
14
+ abort: () => void;
15
+ then: (onfulfilled?: (value: SagaActionResult<Arg, ReturnType>) => void) => Promise<SagaActionResult<Arg, ReturnType>>;
16
+ };
17
+
18
+ interface IRequest {
19
+ requestId: string;
20
+ deferred: Deferred<any>;
21
+ onAdd?: (request: IRequest) => void;
22
+ abort?: () => void;
23
+ }
29
24
 
30
- export interface AsyncSagaThunkConfig {
31
- requestId: string
32
- signal: AbortSignal
33
- abort: (reason?: string) => void
25
+ export type SagaActionResult<Arg, ReturnType> = {
26
+ payload: ReturnType;
27
+ meta: {
28
+ requestId: string;
29
+ arg: Arg;
30
+ };
31
+ error?: SerializedError;
34
32
  }
35
33
 
36
- export function createSagaAction<Returned, ThunkArg = void>(
34
+ export function createSagaAction<PayloadType, ReturnType = void>(
37
35
  type: string
38
- ): AsyncSagaActionCreator<Returned, ThunkArg> & {
36
+ ): {
37
+ (payload: PayloadType): SagaAction<PayloadType, ReturnType>;
39
38
  pending: string;
40
- fulfilled: string;
41
39
  rejected: string;
40
+ fulfilled: string;
42
41
  typePrefix: string;
43
42
  type: string;
44
- }
43
+ };
45
44
 
46
- type SagaFunction<Args extends any[]> = (...args: Args) => SagaIterator;
45
+ export function* getRequest(requestId: string): Generator<CallEffect, IRequest, any>;
47
46
 
48
- export function takeEveryAsync<ActionPattern>(
47
+ export function takeEveryAsync<ActionPattern extends string>(
49
48
  pattern: ActionPattern,
50
- saga: SagaFunction<[...args: any[]]>,
49
+ saga: Saga<[], void>,
51
50
  ...args: any[]
52
- ): void;
51
+ ): ForkEffect<void>;
53
52
 
54
- export function takeLatestAsync<ActionPattern>(
53
+ export function takeLatestAsync<ActionPattern extends string>(
55
54
  pattern: ActionPattern,
56
- saga: SagaFunction<[...args: any[]]>,
55
+ saga: Saga<[], void>,
57
56
  ...args: any[]
58
- ): void;
57
+ ): ForkEffect<void>;
59
58
 
60
- export function takeAggregateAsync<ActionPattern>(
59
+ export function takeAggregateAsync<ActionPattern extends string>(
61
60
  pattern: ActionPattern,
62
- saga: SagaFunction<[...args: any[]]>,
61
+ saga: Saga<[], void>,
63
62
  ...args: any[]
64
- ): void;
63
+ ): ForkEffect<void>;
65
64
 
66
- export function putAsync<T>(action: T): T;
65
+ export function* putAsync<T>(
66
+ action: SagaAction<T>
67
+ ): Generator<PutEffect<SagaAction<T>>, any, any>;
67
68
 
68
- // export function takeEveryAsync(pattern: any, saga: any, ...args: any[]): any
69
- // export function takeLatestAsync(pattern: any, saga: any, ...args: any[]): any
70
- // export function takeAggregateAsync(pattern: any, saga: any, ...args: any[]): any
71
- // export function putAsync(action: any): any
69
+ export type SagaActionFromCreator<Creator extends (...args: any) => any> = SagaActionResult<
70
+ Parameters<Creator>[0],
71
+ void
72
+ > & {
73
+ action: string
74
+ }
72
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saga-toolkit",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "An extension for redux-toolkit that allows sagas to resolve async thunk actions.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -30,7 +30,7 @@
30
30
  "@babel/core": "^7.16.12",
31
31
  "@babel/node": "^7.16.8",
32
32
  "@babel/preset-env": "^7.16.11",
33
- "@reduxjs/toolkit": "^1.7.2",
33
+ "@reduxjs/toolkit": "^1.9.5",
34
34
  "redux": "^4.1.2"
35
35
  }
36
36
  }