@ic-reactor/core 1.0.5 → 1.0.7
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 +1 -1
- package/dist/classes/actor/index.d.ts +1 -1
- package/dist/classes/actor/index.js +22 -23
- package/dist/classes/agent/index.d.ts +1 -1
- package/dist/classes/agent/index.js +12 -9
- package/dist/classes/agent/types.d.ts +1 -1
- package/dist/classes/candid/index.js +1 -1
- package/dist/createActorManager.d.ts +12 -0
- package/dist/createActorManager.js +17 -0
- package/dist/createAgentManager.d.ts +12 -0
- package/dist/createAgentManager.js +17 -0
- package/dist/createCandidAdapter.d.ts +11 -0
- package/dist/createCandidAdapter.js +16 -0
- package/dist/{main.js → createReactorCore.js} +8 -7
- package/dist/{store.js → createReactorStore.js} +8 -7
- package/dist/index.d.ts +6 -4
- package/dist/index.js +7 -5
- package/dist/types.d.ts +1 -1
- package/dist/{tools → utils}/helper.js +4 -2
- package/package.json +2 -2
- package/dist/other.d.ts +0 -33
- package/dist/other.js +0 -44
- /package/dist/{main.d.ts → createReactorCore.d.ts} +0 -0
- /package/dist/{store.d.ts → createReactorStore.d.ts} +0 -0
- /package/dist/{tools → utils}/constants.d.ts +0 -0
- /package/dist/{tools → utils}/constants.js +0 -0
- /package/dist/{tools → utils}/helper.d.ts +0 -0
- /package/dist/{tools → utils}/index.d.ts +0 -0
- /package/dist/{tools → utils}/index.js +0 -0
package/README.md
CHANGED
|
@@ -238,7 +238,7 @@ For development purposes, you might want to connect to a local instance of the I
|
|
|
238
238
|
import { createAgentManager } from "@ic-reactor/core"
|
|
239
239
|
|
|
240
240
|
export const agentManager = createAgentManager({
|
|
241
|
-
|
|
241
|
+
withLocalEnv: true,
|
|
242
242
|
port: 8000, // Default port is 4943
|
|
243
243
|
})
|
|
244
244
|
```
|
|
@@ -17,7 +17,7 @@ export declare class ActorManager<A = BaseActor> {
|
|
|
17
17
|
}>) => void;
|
|
18
18
|
constructor(actorConfig: ActorManagerParameters);
|
|
19
19
|
initialize: (options?: UpdateAgentParameters) => Promise<void>;
|
|
20
|
-
extractService()
|
|
20
|
+
extractService: () => VisitService<A>;
|
|
21
21
|
private initializeActor;
|
|
22
22
|
callMethod: <M extends FunctionName<A>>(functionName: M, ...args: ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
|
|
23
23
|
get agentManager(): AgentManager;
|
|
@@ -12,8 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.ActorManager = void 0;
|
|
13
13
|
/* eslint-disable no-console */
|
|
14
14
|
const agent_1 = require("@dfinity/agent");
|
|
15
|
-
const helper_1 = require("../../
|
|
16
|
-
const candid_1 = require("@dfinity/candid");
|
|
15
|
+
const helper_1 = require("../../utils/helper");
|
|
17
16
|
class ActorManager {
|
|
18
17
|
constructor(actorConfig) {
|
|
19
18
|
this._actor = null;
|
|
@@ -37,6 +36,20 @@ class ActorManager {
|
|
|
37
36
|
this.initialize = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
38
37
|
yield this._agentManager.updateAgent(options);
|
|
39
38
|
});
|
|
39
|
+
this.extractService = () => {
|
|
40
|
+
if (this._actor === null) {
|
|
41
|
+
throw new Error("For extracting service, actor must be initialized");
|
|
42
|
+
}
|
|
43
|
+
return agent_1.Actor.interfaceOf(this._actor)._fields.reduce((acc, service) => {
|
|
44
|
+
const functionName = service[0];
|
|
45
|
+
const type = service[1];
|
|
46
|
+
const visit = ((extractorClass, data) => {
|
|
47
|
+
return type.accept(extractorClass, data || functionName);
|
|
48
|
+
});
|
|
49
|
+
acc[functionName] = visit;
|
|
50
|
+
return acc;
|
|
51
|
+
}, {});
|
|
52
|
+
};
|
|
40
53
|
this.initializeActor = (agent) => {
|
|
41
54
|
console.info(`Initializing actor ${this.canisterId} on ${agent.isLocal() ? "local" : "ic"} network`);
|
|
42
55
|
const { _idlFactory: idlFactory, canisterId } = this;
|
|
@@ -92,35 +105,21 @@ class ActorManager {
|
|
|
92
105
|
return this.actorStore.setState(updater);
|
|
93
106
|
};
|
|
94
107
|
const { agentManager, canisterId, idlFactory, withVisitor = false, withDevtools = false, initializeOnCreate = true, } = actorConfig;
|
|
95
|
-
this._agentManager = agentManager;
|
|
96
|
-
this._agentManager.subscribeAgent(this.initializeActor);
|
|
97
108
|
this.canisterId = canisterId;
|
|
98
109
|
this._idlFactory = idlFactory;
|
|
99
|
-
|
|
100
|
-
this.visitFunction = withVisitor ? this.extractService() : emptyVisitor;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
this.visitFunction = emptyVisitor;
|
|
104
|
-
}
|
|
110
|
+
this._agentManager = agentManager;
|
|
105
111
|
// Initialize stores
|
|
106
112
|
this.actorStore = (0, helper_1.createStoreWithOptionalDevtools)(this.initialState, {
|
|
107
113
|
withDevtools,
|
|
108
114
|
store: `actor-${String(canisterId)}`,
|
|
109
115
|
});
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
this._agentManager.subscribeAgent(this.initializeActor, initializeOnCreate);
|
|
117
|
+
if (withVisitor) {
|
|
118
|
+
this.visitFunction = this.extractService();
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this.visitFunction = emptyVisitor;
|
|
112
122
|
}
|
|
113
|
-
}
|
|
114
|
-
extractService() {
|
|
115
|
-
return this._idlFactory({ IDL: candid_1.IDL })._fields.reduce((acc, service) => {
|
|
116
|
-
const functionName = service[0];
|
|
117
|
-
const type = service[1];
|
|
118
|
-
const visit = ((extractorClass, data) => {
|
|
119
|
-
return type.accept(extractorClass, data || functionName);
|
|
120
|
-
});
|
|
121
|
-
acc[functionName] = visit;
|
|
122
|
-
return acc;
|
|
123
|
-
}, {});
|
|
124
123
|
}
|
|
125
124
|
// agent store
|
|
126
125
|
get agentManager() {
|
|
@@ -13,7 +13,7 @@ export declare class AgentManager {
|
|
|
13
13
|
private updateAuthState;
|
|
14
14
|
constructor(options?: AgentManagerParameters);
|
|
15
15
|
private initializeAgent;
|
|
16
|
-
subscribeAgent: (callback: (agent: HttpAgent) => void) => () => void;
|
|
16
|
+
subscribeAgent: (callback: (agent: HttpAgent) => void, initialize?: boolean) => () => void;
|
|
17
17
|
unsubscribeAgent: (callback: (agent: HttpAgent) => void) => void;
|
|
18
18
|
private notifySubscribers;
|
|
19
19
|
updateAgent: (options?: UpdateAgentParameters) => Promise<void>;
|
|
@@ -45,8 +45,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.AgentManager = void 0;
|
|
47
47
|
const agent_1 = require("@dfinity/agent");
|
|
48
|
-
const helper_1 = require("../../
|
|
49
|
-
const constants_1 = require("../../
|
|
48
|
+
const helper_1 = require("../../utils/helper");
|
|
49
|
+
const constants_1 = require("../../utils/constants");
|
|
50
50
|
class AgentManager {
|
|
51
51
|
constructor(options) {
|
|
52
52
|
this._auth = null;
|
|
@@ -80,16 +80,19 @@ class AgentManager {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
|
-
this.subscribeAgent = (callback) => {
|
|
83
|
+
this.subscribeAgent = (callback, initialize = true) => {
|
|
84
|
+
if (initialize) {
|
|
85
|
+
callback(this._agent);
|
|
86
|
+
}
|
|
84
87
|
this._subscribers.push(callback);
|
|
85
88
|
return () => this.unsubscribeAgent(callback);
|
|
86
89
|
};
|
|
87
90
|
this.unsubscribeAgent = (callback) => {
|
|
88
91
|
this._subscribers = this._subscribers.filter((sub) => sub !== callback);
|
|
89
92
|
};
|
|
90
|
-
this.notifySubscribers = () => {
|
|
91
|
-
this._subscribers.
|
|
92
|
-
};
|
|
93
|
+
this.notifySubscribers = () => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
yield Promise.all(this._subscribers.map((callback) => __awaiter(this, void 0, void 0, function* () { return callback(this._agent); })));
|
|
95
|
+
});
|
|
93
96
|
this.updateAgent = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
94
97
|
const { agent } = options || {};
|
|
95
98
|
if (agent) {
|
|
@@ -100,7 +103,7 @@ class AgentManager {
|
|
|
100
103
|
this.isLocalEnv = this._agent.isLocal();
|
|
101
104
|
yield this.initializeAgent();
|
|
102
105
|
}
|
|
103
|
-
this.notifySubscribers();
|
|
106
|
+
yield this.notifySubscribers();
|
|
104
107
|
});
|
|
105
108
|
this.authenticate = () => __awaiter(this, void 0, void 0, function* () {
|
|
106
109
|
this.updateAuthState({ authenticating: true });
|
|
@@ -154,8 +157,8 @@ class AgentManager {
|
|
|
154
157
|
const identity = this.authStore.getState().identity;
|
|
155
158
|
return identity ? identity.getPrincipal() : null;
|
|
156
159
|
};
|
|
157
|
-
const _a = options || {}, { withDevtools, port = 4943,
|
|
158
|
-
const host =
|
|
160
|
+
const _a = options || {}, { withDevtools, port = 4943, withLocalEnv, host: optionHost } = _a, agentParameters = __rest(_a, ["withDevtools", "port", "withLocalEnv", "host"]);
|
|
161
|
+
const host = withLocalEnv
|
|
159
162
|
? `http://127.0.0.1:${port}`
|
|
160
163
|
: optionHost
|
|
161
164
|
? optionHost.includes("localhost")
|
|
@@ -4,7 +4,7 @@ import type { StoreApi } from "zustand";
|
|
|
4
4
|
export { HttpAgentOptions, AuthClient, Identity };
|
|
5
5
|
export interface AgentManagerParameters extends HttpAgentOptions {
|
|
6
6
|
port?: number;
|
|
7
|
-
|
|
7
|
+
withLocalEnv?: boolean;
|
|
8
8
|
withDevtools?: boolean;
|
|
9
9
|
}
|
|
10
10
|
export interface AgentState {
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.CandidAdapter = void 0;
|
|
13
13
|
const agent_1 = require("@dfinity/agent");
|
|
14
14
|
const principal_1 = require("@dfinity/principal");
|
|
15
|
-
const constants_1 = require("../../
|
|
15
|
+
const constants_1 = require("../../utils/constants");
|
|
16
16
|
class CandidAdapter {
|
|
17
17
|
constructor({ agentManager, agent, didjsCanisterId, }) {
|
|
18
18
|
if (agent) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ActorManager } from "./classes/actor";
|
|
2
|
+
import { ActorManagerParameters, BaseActor } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Actor manager handles the lifecycle of the actors.
|
|
5
|
+
* It is responsible for creating and managing the actors.
|
|
6
|
+
* You can use it to call and visit the actor's methods.
|
|
7
|
+
* It also provides a way to interact with the actor's state.
|
|
8
|
+
*
|
|
9
|
+
* @category Main
|
|
10
|
+
* @includeExample ./packages/core/README.md:262-277
|
|
11
|
+
*/
|
|
12
|
+
export declare const createActorManager: <A = BaseActor>(config: ActorManagerParameters) => ActorManager<A>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createActorManager = void 0;
|
|
4
|
+
const actor_1 = require("./classes/actor");
|
|
5
|
+
/**
|
|
6
|
+
* Actor manager handles the lifecycle of the actors.
|
|
7
|
+
* It is responsible for creating and managing the actors.
|
|
8
|
+
* You can use it to call and visit the actor's methods.
|
|
9
|
+
* It also provides a way to interact with the actor's state.
|
|
10
|
+
*
|
|
11
|
+
* @category Main
|
|
12
|
+
* @includeExample ./packages/core/README.md:262-277
|
|
13
|
+
*/
|
|
14
|
+
const createActorManager = (config) => {
|
|
15
|
+
return new actor_1.ActorManager(config);
|
|
16
|
+
};
|
|
17
|
+
exports.createActorManager = createActorManager;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AgentManager } from "./classes/agent";
|
|
2
|
+
import { AgentManagerParameters } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Agent manager handles the lifecycle of the `@dfinity/agent`.
|
|
5
|
+
* It is responsible for creating agent and managing the agent's state.
|
|
6
|
+
* You can use it to subscribe to the agent changes.
|
|
7
|
+
* login and logout to the internet identity.
|
|
8
|
+
*
|
|
9
|
+
* @category Main
|
|
10
|
+
* @includeExample ./packages/core/README.md:226-254
|
|
11
|
+
*/
|
|
12
|
+
export declare const createAgentManager: (config?: AgentManagerParameters) => AgentManager;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAgentManager = void 0;
|
|
4
|
+
const agent_1 = require("./classes/agent");
|
|
5
|
+
/**
|
|
6
|
+
* Agent manager handles the lifecycle of the `@dfinity/agent`.
|
|
7
|
+
* It is responsible for creating agent and managing the agent's state.
|
|
8
|
+
* You can use it to subscribe to the agent changes.
|
|
9
|
+
* login and logout to the internet identity.
|
|
10
|
+
*
|
|
11
|
+
* @category Main
|
|
12
|
+
* @includeExample ./packages/core/README.md:226-254
|
|
13
|
+
*/
|
|
14
|
+
const createAgentManager = (config) => {
|
|
15
|
+
return new agent_1.AgentManager(config);
|
|
16
|
+
};
|
|
17
|
+
exports.createAgentManager = createAgentManager;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CandidAdapter } from "./classes/candid";
|
|
2
|
+
import { CandidAdapterParameters } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* The `CandidAdapter` class is used to interact with a canister and retrieve its Candid interface definition.
|
|
5
|
+
* It provides methods to fetch the Candid definition either from the canister's metadata or by using a temporary hack method.
|
|
6
|
+
* If both methods fail, it throws an error.
|
|
7
|
+
*
|
|
8
|
+
* @category Main
|
|
9
|
+
* @includeExample ./packages/core/README.md:145-186
|
|
10
|
+
*/
|
|
11
|
+
export declare const createCandidAdapter: (config: CandidAdapterParameters) => CandidAdapter;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCandidAdapter = void 0;
|
|
4
|
+
const candid_1 = require("./classes/candid");
|
|
5
|
+
/**
|
|
6
|
+
* The `CandidAdapter` class is used to interact with a canister and retrieve its Candid interface definition.
|
|
7
|
+
* It provides methods to fetch the Candid definition either from the canister's metadata or by using a temporary hack method.
|
|
8
|
+
* If both methods fail, it throws an error.
|
|
9
|
+
*
|
|
10
|
+
* @category Main
|
|
11
|
+
* @includeExample ./packages/core/README.md:145-186
|
|
12
|
+
*/
|
|
13
|
+
const createCandidAdapter = (config) => {
|
|
14
|
+
return new candid_1.CandidAdapter(config);
|
|
15
|
+
};
|
|
16
|
+
exports.createCandidAdapter = createCandidAdapter;
|
|
@@ -21,9 +21,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.createReactorCore = void 0;
|
|
24
|
-
const constants_1 = require("./
|
|
25
|
-
const
|
|
26
|
-
const
|
|
24
|
+
const constants_1 = require("./utils/constants");
|
|
25
|
+
const utils_1 = require("./utils");
|
|
26
|
+
const createReactorStore_1 = require("./createReactorStore");
|
|
27
27
|
/**
|
|
28
28
|
* The Core module is the main entry point for the library.
|
|
29
29
|
* Create a new actor manager with the given options.
|
|
@@ -33,9 +33,9 @@ const store_1 = require("./store");
|
|
|
33
33
|
* @includeExample ./packages/core/README.md:26-80
|
|
34
34
|
*/
|
|
35
35
|
const createReactorCore = (config) => {
|
|
36
|
-
const _a = (0,
|
|
36
|
+
const _a = (0, createReactorStore_1.createReactorStore)(config), { subscribeActorState, updateMethodState, callMethod, getState, agentManager } = _a, rest = __rest(_a, ["subscribeActorState", "updateMethodState", "callMethod", "getState", "agentManager"]);
|
|
37
37
|
const actorMethod = (functionName, ...args) => {
|
|
38
|
-
const requestHash = (0,
|
|
38
|
+
const requestHash = (0, utils_1.generateRequestHash)(args);
|
|
39
39
|
const updateState = (newState = {}) => {
|
|
40
40
|
updateMethodState(functionName, requestHash, newState);
|
|
41
41
|
};
|
|
@@ -55,6 +55,7 @@ const createReactorCore = (config) => {
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
const subscribe = (callback) => {
|
|
58
|
+
callback(methodState());
|
|
58
59
|
const unsubscribe = subscribeActorState((state) => {
|
|
59
60
|
const methodState = state.methodState[functionName];
|
|
60
61
|
const methodStateHash = methodState[requestHash];
|
|
@@ -122,8 +123,8 @@ const createReactorCore = (config) => {
|
|
|
122
123
|
throw new Error("Auth client not initialized");
|
|
123
124
|
}
|
|
124
125
|
yield authClient.login(Object.assign({ identityProvider: agentManager.isLocalEnv
|
|
125
|
-
? constants_1.
|
|
126
|
-
: constants_1.
|
|
126
|
+
? constants_1.LOCAL_INTERNET_IDENTITY_PROVIDER
|
|
127
|
+
: constants_1.IC_INTERNET_IDENTITY_PROVIDER }, options));
|
|
127
128
|
});
|
|
128
129
|
const logout = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
130
|
const authClient = agentManager.getAuth();
|
|
@@ -12,8 +12,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.createReactorStore = void 0;
|
|
15
|
-
const
|
|
16
|
-
const
|
|
15
|
+
const utils_1 = require("./utils");
|
|
16
|
+
const createActorManager_1 = require("./createActorManager");
|
|
17
|
+
const createAgentManager_1 = require("./createAgentManager");
|
|
17
18
|
/**
|
|
18
19
|
* Create a new actor manager with the given options.
|
|
19
20
|
* Its create a new agent manager if not provided.
|
|
@@ -23,14 +24,14 @@ const tools_1 = require("./tools");
|
|
|
23
24
|
* @includeExample ./packages/core/README.md:194-220
|
|
24
25
|
*/
|
|
25
26
|
const createReactorStore = (config) => {
|
|
26
|
-
const
|
|
27
|
-
? (0,
|
|
27
|
+
const withLocalEnv = config.withProcessEnv
|
|
28
|
+
? (0, utils_1.isInLocalOrDevelopment)()
|
|
28
29
|
: undefined;
|
|
29
30
|
const { idlFactory, canisterId, withDevtools = false, initializeOnCreate = true, withVisitor = false, agentManager: maybeAgentManager } = config, agentParameters = __rest(config, ["idlFactory", "canisterId", "withDevtools", "initializeOnCreate", "withVisitor", "agentManager"]);
|
|
30
31
|
const agentManager = maybeAgentManager ||
|
|
31
|
-
(0,
|
|
32
|
-
|
|
33
|
-
const actorManager = (0,
|
|
32
|
+
(0, createAgentManager_1.createAgentManager)(Object.assign({ withDevtools,
|
|
33
|
+
withLocalEnv }, agentParameters));
|
|
34
|
+
const actorManager = (0, createActorManager_1.createActorManager)({
|
|
34
35
|
idlFactory,
|
|
35
36
|
canisterId,
|
|
36
37
|
agentManager,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
1
|
+
export * from "./createReactorCore";
|
|
2
|
+
export * from "./createReactorStore";
|
|
3
|
+
export * from "./createCandidAdapter";
|
|
4
|
+
export * from "./createActorManager";
|
|
5
|
+
export * from "./createAgentManager";
|
|
4
6
|
export * as classes from "./classes";
|
|
5
7
|
export * as types from "./types";
|
|
6
|
-
export * as
|
|
8
|
+
export * as utils from "./utils";
|
package/dist/index.js
CHANGED
|
@@ -26,10 +26,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
__exportStar(require("./
|
|
31
|
-
__exportStar(require("./
|
|
32
|
-
__exportStar(require("./
|
|
29
|
+
exports.utils = exports.types = exports.classes = void 0;
|
|
30
|
+
__exportStar(require("./createReactorCore"), exports);
|
|
31
|
+
__exportStar(require("./createReactorStore"), exports);
|
|
32
|
+
__exportStar(require("./createCandidAdapter"), exports);
|
|
33
|
+
__exportStar(require("./createActorManager"), exports);
|
|
34
|
+
__exportStar(require("./createAgentManager"), exports);
|
|
33
35
|
exports.classes = __importStar(require("./classes"));
|
|
34
36
|
exports.types = __importStar(require("./types"));
|
|
35
|
-
exports.
|
|
37
|
+
exports.utils = __importStar(require("./utils"));
|
package/dist/types.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type { ActorMethod, AuthClientLoginOptions, HttpAgentOptions, ActorSubcla
|
|
|
14
14
|
export interface CreateReactorStoreParameters extends HttpAgentOptions, Omit<ActorManagerParameters, "agentManager"> {
|
|
15
15
|
agentManager?: AgentManager;
|
|
16
16
|
withProcessEnv?: boolean;
|
|
17
|
-
|
|
17
|
+
withLocalEnv?: boolean;
|
|
18
18
|
port?: number;
|
|
19
19
|
}
|
|
20
20
|
export type ActorGetStateFunction<A, M extends FunctionName<A>> = {
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stringToHash = exports.generateActorHash = exports.generateHash = exports.generateRequestHash = exports.jsonToString = exports.isInLocalOrDevelopment = exports.createStoreWithOptionalDevtools = void 0;
|
|
4
4
|
const agent_1 = require("@dfinity/agent");
|
|
5
|
-
const candid_1 = require("@dfinity/candid");
|
|
6
5
|
const middleware_1 = require("zustand/middleware");
|
|
7
6
|
const vanilla_1 = require("zustand/vanilla");
|
|
8
7
|
function createStoreWithOptionalDevtools(initialState, config) {
|
|
@@ -51,6 +50,9 @@ const generateActorHash = (actor) => {
|
|
|
51
50
|
exports.generateActorHash = generateActorHash;
|
|
52
51
|
const stringToHash = (str) => {
|
|
53
52
|
const hashBytes = (0, agent_1.hash)(new TextEncoder().encode(str));
|
|
54
|
-
return `0x${
|
|
53
|
+
return `0x${toHexString(hashBytes)}`;
|
|
55
54
|
};
|
|
56
55
|
exports.stringToHash = stringToHash;
|
|
56
|
+
function toHexString(bytes) {
|
|
57
|
+
return new Uint8Array(bytes).reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "A library for intracting with the Internet Computer canisters",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=10"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "ed812d516651ec01414d9a1a79e959d8cc139a93"
|
|
47
47
|
}
|
package/dist/other.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ActorManager } from "./classes/actor";
|
|
2
|
-
import { AgentManager } from "./classes/agent";
|
|
3
|
-
import { CandidAdapter } from "./classes/candid";
|
|
4
|
-
import { CandidAdapterParameters, ActorManagerParameters, AgentManagerParameters, BaseActor } from "./types";
|
|
5
|
-
/**
|
|
6
|
-
* The `CandidAdapter` class is used to interact with a canister and retrieve its Candid interface definition.
|
|
7
|
-
* It provides methods to fetch the Candid definition either from the canister's metadata or by using a temporary hack method.
|
|
8
|
-
* If both methods fail, it throws an error.
|
|
9
|
-
*
|
|
10
|
-
* @category Main
|
|
11
|
-
* @includeExample ./packages/core/README.md:145-186
|
|
12
|
-
*/
|
|
13
|
-
export declare const createCandidAdapter: (config: CandidAdapterParameters) => CandidAdapter;
|
|
14
|
-
/**
|
|
15
|
-
* Agent manager handles the lifecycle of the `@dfinity/agent`.
|
|
16
|
-
* It is responsible for creating agent and managing the agent's state.
|
|
17
|
-
* You can use it to subscribe to the agent changes.
|
|
18
|
-
* login and logout to the internet identity.
|
|
19
|
-
*
|
|
20
|
-
* @category Main
|
|
21
|
-
* @includeExample ./packages/core/README.md:226-254
|
|
22
|
-
*/
|
|
23
|
-
export declare const createAgentManager: (config?: AgentManagerParameters) => AgentManager;
|
|
24
|
-
/**
|
|
25
|
-
* Actor manager handles the lifecycle of the actors.
|
|
26
|
-
* It is responsible for creating and managing the actors.
|
|
27
|
-
* You can use it to call and visit the actor's methods.
|
|
28
|
-
* It also provides a way to interact with the actor's state.
|
|
29
|
-
*
|
|
30
|
-
* @category Main
|
|
31
|
-
* @includeExample ./packages/core/README.md:262-277
|
|
32
|
-
*/
|
|
33
|
-
export declare const createActorManager: <A = BaseActor>(config: ActorManagerParameters) => ActorManager<A>;
|
package/dist/other.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createActorManager = exports.createAgentManager = exports.createCandidAdapter = void 0;
|
|
4
|
-
const actor_1 = require("./classes/actor");
|
|
5
|
-
const agent_1 = require("./classes/agent");
|
|
6
|
-
const candid_1 = require("./classes/candid");
|
|
7
|
-
/**
|
|
8
|
-
* The `CandidAdapter` class is used to interact with a canister and retrieve its Candid interface definition.
|
|
9
|
-
* It provides methods to fetch the Candid definition either from the canister's metadata or by using a temporary hack method.
|
|
10
|
-
* If both methods fail, it throws an error.
|
|
11
|
-
*
|
|
12
|
-
* @category Main
|
|
13
|
-
* @includeExample ./packages/core/README.md:145-186
|
|
14
|
-
*/
|
|
15
|
-
const createCandidAdapter = (config) => {
|
|
16
|
-
return new candid_1.CandidAdapter(config);
|
|
17
|
-
};
|
|
18
|
-
exports.createCandidAdapter = createCandidAdapter;
|
|
19
|
-
/**
|
|
20
|
-
* Agent manager handles the lifecycle of the `@dfinity/agent`.
|
|
21
|
-
* It is responsible for creating agent and managing the agent's state.
|
|
22
|
-
* You can use it to subscribe to the agent changes.
|
|
23
|
-
* login and logout to the internet identity.
|
|
24
|
-
*
|
|
25
|
-
* @category Main
|
|
26
|
-
* @includeExample ./packages/core/README.md:226-254
|
|
27
|
-
*/
|
|
28
|
-
const createAgentManager = (config) => {
|
|
29
|
-
return new agent_1.AgentManager(config);
|
|
30
|
-
};
|
|
31
|
-
exports.createAgentManager = createAgentManager;
|
|
32
|
-
/**
|
|
33
|
-
* Actor manager handles the lifecycle of the actors.
|
|
34
|
-
* It is responsible for creating and managing the actors.
|
|
35
|
-
* You can use it to call and visit the actor's methods.
|
|
36
|
-
* It also provides a way to interact with the actor's state.
|
|
37
|
-
*
|
|
38
|
-
* @category Main
|
|
39
|
-
* @includeExample ./packages/core/README.md:262-277
|
|
40
|
-
*/
|
|
41
|
-
const createActorManager = (config) => {
|
|
42
|
-
return new actor_1.ActorManager(config);
|
|
43
|
-
};
|
|
44
|
-
exports.createActorManager = createActorManager;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|