@ic-reactor/core 0.3.0 → 0.3.1
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.ts +11 -8
- package/dist/index.js +5 -4
- package/dist/types.d.ts +10 -10
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CreateReActorOptions } from "@ic-reactor/store";
|
|
2
2
|
import { ReActorQuery, ReActorUpdate } from "./types";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export declare const createReActor: <A extends unknown>(options: CreateReActorOptions) => {
|
|
4
|
+
methodFields: import("@ic-reactor/store").ActorMethodField<A>[];
|
|
5
|
+
unsubscribeActor: () => void;
|
|
6
|
+
updateMethodState: (newState: Partial<import("@ic-reactor/store").ActorMethodStates<A>>) => void;
|
|
7
|
+
subscribeAgent: (callback: (agent: import("@ic-reactor/store").HttpAgent) => void) => () => void;
|
|
8
|
+
unsubscribeAgent: (callback: (agent: import("@ic-reactor/store").HttpAgent) => void) => void;
|
|
9
|
+
updateAgent: (agent: import("@ic-reactor/store").HttpAgent) => void;
|
|
8
10
|
authenticate: () => Promise<void>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
getAgent: () => import("@ic-reactor/store").HttpAgent;
|
|
12
|
+
actorStore: import("@ic-reactor/store").ActorStore<A>;
|
|
13
|
+
authStore: import("@ic-reactor/store").AuthenticateStore;
|
|
11
14
|
queryCall: ReActorQuery<A>;
|
|
12
15
|
updateCall: ReActorUpdate<A>;
|
|
13
16
|
};
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
exports.createReActor = void 0;
|
|
24
24
|
const store_1 = require("@ic-reactor/store");
|
|
25
25
|
const createReActor = (options) => {
|
|
26
|
-
const _a = (0, store_1.createReActorStore)(options), { callMethod, actorStore
|
|
26
|
+
const _a = (0, store_1.createReActorStore)(options), { agentManager, callMethod, actorStore } = _a, rest = __rest(_a, ["agentManager", "callMethod", "actorStore"]);
|
|
27
|
+
const { authStore } = agentManager, agentRest = __rest(agentManager, ["authStore"]);
|
|
27
28
|
const updateMethodState = (method, args = [], newState) => {
|
|
28
29
|
const hash = (0, store_1.generateRequestHash)(args);
|
|
29
30
|
actorStore.setState((state) => {
|
|
@@ -114,14 +115,14 @@ const createReActor = (options) => {
|
|
|
114
115
|
let initialData = Promise.resolve();
|
|
115
116
|
if (!disableInitialCall)
|
|
116
117
|
initialData = call();
|
|
117
|
-
return Object.assign(Object.assign({}, rest), {
|
|
118
|
+
return Object.assign(Object.assign({}, rest), { call, initialData, intervalId });
|
|
118
119
|
};
|
|
119
120
|
const updateCall = ({ functionName, args = [] }) => {
|
|
120
121
|
return reActorMethod(functionName, ...args);
|
|
121
122
|
};
|
|
122
|
-
return Object.assign({ actorStore,
|
|
123
|
+
return Object.assign(Object.assign({ actorStore,
|
|
123
124
|
authStore,
|
|
124
125
|
queryCall,
|
|
125
|
-
updateCall }, rest);
|
|
126
|
+
updateCall }, agentRest), rest);
|
|
126
127
|
};
|
|
127
128
|
exports.createReActor = createReActor;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ActorMethod, ActorSubclass,
|
|
2
|
+
import type { ActorMethod, ActorSubclass, ExtractActorMethodArgs, ExtractActorMethodReturnType, ActorMethodState } from "@ic-reactor/store";
|
|
3
3
|
export type ReActorGetStateFunction<A, M extends keyof A> = {
|
|
4
|
-
(key: "data"):
|
|
4
|
+
(key: "data"): ExtractActorMethodReturnType<A[M]> | undefined;
|
|
5
5
|
(key: "loading"): boolean;
|
|
6
6
|
(key: "error"): Error | undefined;
|
|
7
|
-
():
|
|
7
|
+
(): ActorMethodState<A, M>[string];
|
|
8
8
|
};
|
|
9
|
-
export type ReActorSubscribeFunction<A, M extends keyof A> = (callback: (state:
|
|
10
|
-
export type ReActorCallFunction<A, M extends keyof A> = (replaceArgs?:
|
|
9
|
+
export type ReActorSubscribeFunction<A, M extends keyof A> = (callback: (state: ActorMethodState<A, M>[string]) => void) => () => void;
|
|
10
|
+
export type ReActorCallFunction<A, M extends keyof A> = (replaceArgs?: ExtractActorMethodArgs<A[M]>) => Promise<ExtractActorMethodReturnType<A[M]> | undefined>;
|
|
11
11
|
export type ReActorQueryReturn<A, M extends keyof A> = {
|
|
12
12
|
intervalId: NodeJS.Timeout | null;
|
|
13
13
|
requestHash: string;
|
|
14
14
|
getState: ReActorGetStateFunction<A, M>;
|
|
15
15
|
subscribe: ReActorSubscribeFunction<A, M>;
|
|
16
|
-
|
|
17
|
-
initialData: Promise<
|
|
16
|
+
call: ReActorCallFunction<A, M>;
|
|
17
|
+
initialData: Promise<ExtractActorMethodReturnType<A[M]> | undefined>;
|
|
18
18
|
};
|
|
19
19
|
export type ReActorUpdateReturn<A, M extends keyof A> = {
|
|
20
20
|
requestHash: string;
|
|
@@ -24,16 +24,16 @@ export type ReActorUpdateReturn<A, M extends keyof A> = {
|
|
|
24
24
|
};
|
|
25
25
|
export type ReActorQueryArgs<A, M extends keyof A> = {
|
|
26
26
|
functionName: M;
|
|
27
|
-
args?:
|
|
27
|
+
args?: ExtractActorMethodArgs<A[M]>;
|
|
28
28
|
disableInitialCall?: boolean;
|
|
29
29
|
autoRefresh?: boolean;
|
|
30
30
|
refreshInterval?: number;
|
|
31
31
|
};
|
|
32
32
|
export type ReActorUpdateArgs<A, M extends keyof A> = {
|
|
33
33
|
functionName: M;
|
|
34
|
-
args?:
|
|
34
|
+
args?: ExtractActorMethodArgs<A[M]>;
|
|
35
35
|
};
|
|
36
|
-
export type ReActorMethod<A = Record<string, ActorMethod>> = <M extends keyof A>(functionName: M, ...args:
|
|
36
|
+
export type ReActorMethod<A = Record<string, ActorMethod>> = <M extends keyof A>(functionName: M, ...args: ExtractActorMethodArgs<A[M]>) => ReActorUpdateReturn<A, M>;
|
|
37
37
|
export type ReActorQuery<A = Record<string, ActorMethod>> = <M extends keyof A>(options: ReActorQueryArgs<A, M>) => ReActorQueryReturn<A, M>;
|
|
38
38
|
export type ReActorUpdate<A = Record<string, ActorMethod>> = <M extends keyof A>(options: ReActorUpdateArgs<A, M>) => ReActorUpdateReturn<A, M>;
|
|
39
39
|
export interface ReActorCoreActions<A extends ActorSubclass<any>> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A React library for interacting with Dfinity actors",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"node": ">=10"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ic-reactor/store": "^0.3.
|
|
38
|
+
"@ic-reactor/store": "^0.3.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@dfinity/agent": "^0.20",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@peculiar/webcrypto": "1.4",
|
|
47
47
|
"zustand": "4.4"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "c1204b00b5faca2d75911a684fdbc1e341f610a4"
|
|
50
50
|
}
|