@ic-reactor/core 1.0.5 → 1.0.6
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/classes/actor/index.js +3 -6
- package/dist/classes/agent/index.d.ts +1 -1
- package/dist/classes/agent/index.js +6 -3
- 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} +6 -5
- package/dist/index.d.ts +6 -4
- package/dist/index.js +7 -5
- 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}/helper.js +0 -0
- /package/dist/{tools → utils}/index.d.ts +0 -0
- /package/dist/{tools → utils}/index.js +0 -0
|
@@ -12,7 +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("../../
|
|
15
|
+
const helper_1 = require("../../utils/helper");
|
|
16
16
|
const candid_1 = require("@dfinity/candid");
|
|
17
17
|
class ActorManager {
|
|
18
18
|
constructor(actorConfig) {
|
|
@@ -92,10 +92,9 @@ class ActorManager {
|
|
|
92
92
|
return this.actorStore.setState(updater);
|
|
93
93
|
};
|
|
94
94
|
const { agentManager, canisterId, idlFactory, withVisitor = false, withDevtools = false, initializeOnCreate = true, } = actorConfig;
|
|
95
|
-
this._agentManager = agentManager;
|
|
96
|
-
this._agentManager.subscribeAgent(this.initializeActor);
|
|
97
95
|
this.canisterId = canisterId;
|
|
98
96
|
this._idlFactory = idlFactory;
|
|
97
|
+
this._agentManager = agentManager;
|
|
99
98
|
if (withVisitor) {
|
|
100
99
|
this.visitFunction = withVisitor ? this.extractService() : emptyVisitor;
|
|
101
100
|
}
|
|
@@ -107,9 +106,7 @@ class ActorManager {
|
|
|
107
106
|
withDevtools,
|
|
108
107
|
store: `actor-${String(canisterId)}`,
|
|
109
108
|
});
|
|
110
|
-
|
|
111
|
-
this.initializeActor(agentManager.getAgent());
|
|
112
|
-
}
|
|
109
|
+
this._agentManager.subscribeAgent(this.initializeActor, initializeOnCreate);
|
|
113
110
|
}
|
|
114
111
|
extractService() {
|
|
115
112
|
return this._idlFactory({ IDL: candid_1.IDL })._fields.reduce((acc, service) => {
|
|
@@ -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,7 +80,10 @@ 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
|
};
|
|
@@ -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.
|
|
@@ -24,13 +25,13 @@ const tools_1 = require("./tools");
|
|
|
24
25
|
*/
|
|
25
26
|
const createReactorStore = (config) => {
|
|
26
27
|
const isLocalEnv = config.withProcessEnv
|
|
27
|
-
? (0,
|
|
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
|
+
(0, createAgentManager_1.createAgentManager)(Object.assign({ withDevtools,
|
|
32
33
|
isLocalEnv }, agentParameters));
|
|
33
|
-
const actorManager = (0,
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
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": "bf69ae06def96cd40814a72535325f7c7a8a6b5a"
|
|
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
|
|
File without changes
|