saga-toolkit 2.1.0 → 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 +63 -38
  2. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -1,50 +1,75 @@
1
- // generated with chatGTP
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';
2
4
 
3
5
  declare module 'saga-toolkit' {
4
- import { createAsyncThunk, ThunkAction } from '@reduxjs/toolkit'
5
- import { Dispatch } from 'redux'
6
- import { SagaIterator } from 'redux-saga'
7
- import { ActionCreatorWithPayload } from '@reduxjs/toolkit/src/createAction'
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
- ) => ActionCreatorWithPayload<
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
- >
29
-
30
- export interface AsyncSagaThunkConfig {
31
- requestId: string
32
- signal: AbortSignal
33
- abort: (reason?: string) => void
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
+ }
24
+
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
- export function takeEveryAsync(pattern: any, saga: any, ...args: any[]): any
47
- export function takeLatestAsync(pattern: any, saga: any, ...args: any[]): any
48
- export function takeAggregateAsync(pattern: any, saga: any, ...args: any[]): any
49
- export function putAsync(action: any): any
45
+ export function* getRequest(requestId: string): Generator<CallEffect, IRequest, any>;
46
+
47
+ export function takeEveryAsync<ActionPattern extends string>(
48
+ pattern: ActionPattern,
49
+ saga: Saga<[], void>,
50
+ ...args: any[]
51
+ ): ForkEffect<void>;
52
+
53
+ export function takeLatestAsync<ActionPattern extends string>(
54
+ pattern: ActionPattern,
55
+ saga: Saga<[], void>,
56
+ ...args: any[]
57
+ ): ForkEffect<void>;
58
+
59
+ export function takeAggregateAsync<ActionPattern extends string>(
60
+ pattern: ActionPattern,
61
+ saga: Saga<[], void>,
62
+ ...args: any[]
63
+ ): ForkEffect<void>;
64
+
65
+ export function* putAsync<T>(
66
+ action: SagaAction<T>
67
+ ): Generator<PutEffect<SagaAction<T>>, any, any>;
68
+
69
+ export type SagaActionFromCreator<Creator extends (...args: any) => any> = SagaActionResult<
70
+ Parameters<Creator>[0],
71
+ void
72
+ > & {
73
+ action: string
74
+ }
50
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saga-toolkit",
3
- "version": "2.1.0",
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
  }