@ic-reactor/core 2.0.0 → 3.0.0-beta.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/client.d.ts +161 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +499 -0
- package/dist/client.js.map +1 -0
- package/dist/display/helper.d.ts +10 -0
- package/dist/display/helper.d.ts.map +1 -0
- package/dist/display/helper.js +67 -0
- package/dist/display/helper.js.map +1 -0
- package/dist/display/index.d.ts +4 -0
- package/dist/display/index.d.ts.map +1 -0
- package/dist/display/index.js +4 -0
- package/dist/display/index.js.map +1 -0
- package/dist/display/types.d.ts +31 -0
- package/dist/display/types.d.ts.map +1 -0
- package/dist/display/types.js +2 -0
- package/dist/display/types.js.map +1 -0
- package/dist/display/visitor.d.ts +28 -0
- package/dist/display/visitor.d.ts.map +1 -0
- package/dist/display/visitor.js +318 -0
- package/dist/display/visitor.js.map +1 -0
- package/dist/display-reactor.d.ts +245 -0
- package/dist/display-reactor.d.ts.map +1 -0
- package/dist/display-reactor.js +331 -0
- package/dist/display-reactor.js.map +1 -0
- package/dist/errors/index.d.ts +118 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +204 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -47
- package/dist/index.js.map +1 -0
- package/dist/reactor.d.ts +133 -0
- package/dist/reactor.d.ts.map +1 -0
- package/dist/reactor.js +325 -0
- package/dist/reactor.js.map +1 -0
- package/dist/types/client.d.ts +89 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/client.js +2 -0
- package/dist/types/client.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/reactor.d.ts +117 -0
- package/dist/types/reactor.d.ts.map +1 -0
- package/dist/types/reactor.js +2 -0
- package/dist/types/reactor.js.map +1 -0
- package/dist/types/result.d.ts +48 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +2 -0
- package/dist/types/result.js.map +1 -0
- package/dist/types/transform.d.ts +7 -0
- package/dist/types/transform.d.ts.map +1 -0
- package/dist/types/transform.js +2 -0
- package/dist/types/transform.js.map +1 -0
- package/dist/types/variant.d.ts +18 -0
- package/dist/types/variant.d.ts.map +1 -0
- package/dist/types/variant.js +2 -0
- package/dist/types/variant.js.map +1 -0
- package/dist/utils/agent.d.ts +30 -1
- package/dist/utils/agent.d.ts.map +1 -0
- package/dist/utils/agent.js +118 -16
- package/dist/utils/agent.js.map +1 -0
- package/dist/utils/candid.d.ts +39 -1
- package/dist/utils/candid.d.ts.map +1 -0
- package/dist/utils/candid.js +76 -16
- package/dist/utils/candid.js.map +1 -0
- package/dist/utils/constants.d.ts +3 -4
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +7 -11
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/helper.d.ts +16 -39
- package/dist/utils/helper.d.ts.map +1 -0
- package/dist/utils/helper.js +53 -155
- package/dist/utils/helper.js.map +1 -0
- package/dist/utils/index.d.ts +4 -5
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -49
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/polling.d.ts +176 -0
- package/dist/utils/polling.d.ts.map +1 -0
- package/dist/utils/polling.js +170 -0
- package/dist/utils/polling.js.map +1 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +65 -39
- package/LICENSE.md +0 -8
- package/README.md +0 -283
- package/dist/classes/actor/index.d.ts +0 -34
- package/dist/classes/actor/index.js +0 -245
- package/dist/classes/actor/types.d.ts +0 -113
- package/dist/classes/actor/types.js +0 -2
- package/dist/classes/adapter/index.d.ts +0 -19
- package/dist/classes/adapter/index.js +0 -140
- package/dist/classes/adapter/types.d.ts +0 -14
- package/dist/classes/adapter/types.js +0 -2
- package/dist/classes/agent/index.d.ts +0 -36
- package/dist/classes/agent/index.js +0 -218
- package/dist/classes/agent/types.d.ts +0 -87
- package/dist/classes/agent/types.js +0 -2
- package/dist/classes/index.d.ts +0 -3
- package/dist/classes/index.js +0 -19
- package/dist/classes/types.d.ts +0 -15
- package/dist/classes/types.js +0 -20
- package/dist/createActorManager.d.ts +0 -12
- package/dist/createActorManager.js +0 -17
- package/dist/createAgentManager.d.ts +0 -12
- package/dist/createAgentManager.js +0 -17
- package/dist/createCandidAdapter.d.ts +0 -11
- package/dist/createCandidAdapter.js +0 -16
- package/dist/createReactorCore.d.ts +0 -10
- package/dist/createReactorCore.js +0 -112
- package/dist/createReactorStore.d.ts +0 -11
- package/dist/createReactorStore.js +0 -31
- package/dist/types.d.ts +0 -96
- package/dist/types.js +0 -17
- package/dist/utils/hash.d.ts +0 -12
- package/dist/utils/hash.js +0 -70
- package/dist/utils/principal.d.ts +0 -1
- package/dist/utils/principal.js +0 -17
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgentManager = void 0;
|
|
4
|
-
/* eslint-disable no-console */
|
|
5
|
-
const agent_1 = require("@dfinity/agent");
|
|
6
|
-
const helper_1 = require("../../utils/helper");
|
|
7
|
-
const auth_client_1 = require("@dfinity/auth-client");
|
|
8
|
-
const constants_1 = require("../../utils/constants");
|
|
9
|
-
const AGENT_INITIAL_STATE = {
|
|
10
|
-
initialized: false,
|
|
11
|
-
isInitialized: false,
|
|
12
|
-
initializing: false,
|
|
13
|
-
isInitializing: false,
|
|
14
|
-
error: undefined,
|
|
15
|
-
network: undefined,
|
|
16
|
-
};
|
|
17
|
-
const AUTH_INITIAL_STATE = {
|
|
18
|
-
identity: null,
|
|
19
|
-
authenticating: false,
|
|
20
|
-
isAuthenticating: false,
|
|
21
|
-
authenticated: false,
|
|
22
|
-
isAuthenticated: false,
|
|
23
|
-
error: undefined,
|
|
24
|
-
};
|
|
25
|
-
class AgentManager {
|
|
26
|
-
_agent;
|
|
27
|
-
_auth = null;
|
|
28
|
-
_subscribers = [];
|
|
29
|
-
agentStore;
|
|
30
|
-
authStore;
|
|
31
|
-
updateAgentState = (newState, action) => {
|
|
32
|
-
this.agentStore.setState((state) => ({ ...state, ...newState }), false, action);
|
|
33
|
-
};
|
|
34
|
-
updateAuthState = (newState, action) => {
|
|
35
|
-
this.authStore.setState((state) => ({ ...state, ...newState }), false, action);
|
|
36
|
-
};
|
|
37
|
-
constructor(options) {
|
|
38
|
-
const { withDevtools, port = 4943, withLocalEnv, withProcessEnv, initializeOnCreate = true, ...agentOptions } = options || {};
|
|
39
|
-
if (withProcessEnv) {
|
|
40
|
-
const processNetwork = (0, helper_1.getProcessEnvNetwork)();
|
|
41
|
-
agentOptions.host =
|
|
42
|
-
processNetwork === "ic" ? constants_1.IC_HOST_NETWORK_URI : undefined;
|
|
43
|
-
}
|
|
44
|
-
else if (withLocalEnv) {
|
|
45
|
-
agentOptions.host = `http://127.0.0.1:${port}`;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
agentOptions.host = agentOptions.host ?? constants_1.IC_HOST_NETWORK_URI;
|
|
49
|
-
}
|
|
50
|
-
this.agentStore = (0, helper_1.createStoreWithOptionalDevtools)(AGENT_INITIAL_STATE, {
|
|
51
|
-
withDevtools,
|
|
52
|
-
name: "reactor-agent",
|
|
53
|
-
store: "agent",
|
|
54
|
-
});
|
|
55
|
-
this.authStore = (0, helper_1.createStoreWithOptionalDevtools)(AUTH_INITIAL_STATE, {
|
|
56
|
-
withDevtools,
|
|
57
|
-
name: "reactor-agent",
|
|
58
|
-
store: "auth",
|
|
59
|
-
});
|
|
60
|
-
this._agent = agent_1.HttpAgent.createSync(agentOptions);
|
|
61
|
-
if (initializeOnCreate) {
|
|
62
|
-
this.initializeAgent();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
initializeAgent = async () => {
|
|
66
|
-
const network = this.getNetwork();
|
|
67
|
-
this.updateAgentState({
|
|
68
|
-
initializing: true,
|
|
69
|
-
isInitializing: true,
|
|
70
|
-
error: undefined,
|
|
71
|
-
network,
|
|
72
|
-
}, "initializing");
|
|
73
|
-
if (network !== "ic") {
|
|
74
|
-
try {
|
|
75
|
-
await this._agent.fetchRootKey();
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
this.updateAgentState({
|
|
79
|
-
error: error,
|
|
80
|
-
initializing: false,
|
|
81
|
-
isInitializing: false,
|
|
82
|
-
}, "error");
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
this.updateAgentState({
|
|
86
|
-
initialized: true,
|
|
87
|
-
isInitialized: true,
|
|
88
|
-
initializing: false,
|
|
89
|
-
isInitializing: false,
|
|
90
|
-
}, "initialized");
|
|
91
|
-
};
|
|
92
|
-
subscribeAgent = (callback, initialize = true) => {
|
|
93
|
-
if (initialize) {
|
|
94
|
-
callback(this._agent);
|
|
95
|
-
}
|
|
96
|
-
this._subscribers.push(callback);
|
|
97
|
-
return () => this.unsubscribeAgent(callback);
|
|
98
|
-
};
|
|
99
|
-
unsubscribeAgent = (callback) => {
|
|
100
|
-
this._subscribers = this._subscribers.filter((sub) => sub !== callback);
|
|
101
|
-
};
|
|
102
|
-
notifySubscribers = async () => {
|
|
103
|
-
await Promise.all(this._subscribers.map(async (callback) => callback(this._agent)));
|
|
104
|
-
};
|
|
105
|
-
updateAgent = async (options) => {
|
|
106
|
-
const { agent } = options || {};
|
|
107
|
-
if (agent) {
|
|
108
|
-
this._agent = agent;
|
|
109
|
-
}
|
|
110
|
-
else if (options) {
|
|
111
|
-
this._agent = agent_1.HttpAgent.createSync(options);
|
|
112
|
-
await this.initializeAgent();
|
|
113
|
-
}
|
|
114
|
-
await this.notifySubscribers();
|
|
115
|
-
};
|
|
116
|
-
authenticate = async () => {
|
|
117
|
-
console.log(`Authenticating on ${this.getNetwork()} network`);
|
|
118
|
-
this.updateAuthState({ isAuthenticating: true, authenticating: true }, "authenticating");
|
|
119
|
-
try {
|
|
120
|
-
this._auth = await auth_client_1.AuthClient.create();
|
|
121
|
-
const isAuthenticated = await this._auth.isAuthenticated();
|
|
122
|
-
const identity = this._auth.getIdentity();
|
|
123
|
-
this._agent.replaceIdentity(identity);
|
|
124
|
-
this.notifySubscribers();
|
|
125
|
-
this.updateAuthState({
|
|
126
|
-
authenticated: isAuthenticated,
|
|
127
|
-
isAuthenticated,
|
|
128
|
-
identity,
|
|
129
|
-
authenticating: false,
|
|
130
|
-
isAuthenticating: false,
|
|
131
|
-
}, "authenticated");
|
|
132
|
-
return identity;
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
this.updateAuthState({
|
|
136
|
-
error: error,
|
|
137
|
-
isAuthenticating: false,
|
|
138
|
-
authenticating: false,
|
|
139
|
-
}, "error");
|
|
140
|
-
throw error;
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
login = async (options) => {
|
|
144
|
-
this.updateAuthState({ isAuthenticating: true, authenticating: true }, "login");
|
|
145
|
-
if (!this._auth) {
|
|
146
|
-
await this.authenticate();
|
|
147
|
-
}
|
|
148
|
-
if (!this._auth) {
|
|
149
|
-
throw new Error("Auth client not initialized");
|
|
150
|
-
}
|
|
151
|
-
await this._auth.login({
|
|
152
|
-
identityProvider: this.getIsLocal()
|
|
153
|
-
? constants_1.LOCAL_INTERNET_IDENTITY_PROVIDER
|
|
154
|
-
: constants_1.IC_INTERNET_IDENTITY_PROVIDER,
|
|
155
|
-
...options,
|
|
156
|
-
onSuccess: async (msg) => {
|
|
157
|
-
await this.authenticate();
|
|
158
|
-
options?.onSuccess?.(msg);
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
logout = async (options) => {
|
|
163
|
-
if (!this._auth) {
|
|
164
|
-
throw new Error("Auth client not initialized");
|
|
165
|
-
}
|
|
166
|
-
await this._auth.logout(options);
|
|
167
|
-
await this.authenticate();
|
|
168
|
-
};
|
|
169
|
-
// agent store
|
|
170
|
-
getAgent = () => {
|
|
171
|
-
return this._agent;
|
|
172
|
-
};
|
|
173
|
-
getAgentHost = () => {
|
|
174
|
-
return this._agent.host;
|
|
175
|
-
};
|
|
176
|
-
getAgentHostName = () => {
|
|
177
|
-
return this.getAgentHost()?.hostname || "";
|
|
178
|
-
};
|
|
179
|
-
getIsLocal = () => {
|
|
180
|
-
return this.getNetwork() !== "ic";
|
|
181
|
-
};
|
|
182
|
-
getNetwork = () => {
|
|
183
|
-
const hostname = this.getAgentHostName();
|
|
184
|
-
return (0, helper_1.getNetworkByHostname)(hostname);
|
|
185
|
-
};
|
|
186
|
-
getAgentState = () => {
|
|
187
|
-
return this.agentStore.getState();
|
|
188
|
-
};
|
|
189
|
-
// @ts-expect-error: Overrides subscribe method signature
|
|
190
|
-
subscribeAgentState = (selectorOrListener, listener, options) => {
|
|
191
|
-
if (listener) {
|
|
192
|
-
return this.agentStore.subscribe(selectorOrListener, listener, options);
|
|
193
|
-
}
|
|
194
|
-
return this.agentStore.subscribe(selectorOrListener);
|
|
195
|
-
};
|
|
196
|
-
// auth store
|
|
197
|
-
getAuthState = () => {
|
|
198
|
-
return this.authStore.getState();
|
|
199
|
-
};
|
|
200
|
-
// @ts-expect-error: Overrides subscribe method signature
|
|
201
|
-
subscribeAuthState = (selectorOrListener, listener, options) => {
|
|
202
|
-
if (listener) {
|
|
203
|
-
return this.authStore.subscribe(selectorOrListener, listener, options);
|
|
204
|
-
}
|
|
205
|
-
return this.authStore.subscribe(selectorOrListener);
|
|
206
|
-
};
|
|
207
|
-
getAuth = () => {
|
|
208
|
-
return this._auth;
|
|
209
|
-
};
|
|
210
|
-
getIdentity = () => {
|
|
211
|
-
return this.authStore.getState().identity;
|
|
212
|
-
};
|
|
213
|
-
getPrincipal = () => {
|
|
214
|
-
const identity = this.authStore.getState().identity;
|
|
215
|
-
return identity ? identity.getPrincipal() : null;
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
exports.AgentManager = AgentManager;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { AgentError, HttpAgent, HttpAgentOptions, Identity } from "@dfinity/agent";
|
|
2
|
-
import type { AuthClient } from "@dfinity/auth-client";
|
|
3
|
-
import type { StoreWithAllMiddleware } from "../../types";
|
|
4
|
-
export { HttpAgentOptions, AuthClient, Identity };
|
|
5
|
-
/**
|
|
6
|
-
* Parameters for configuring an AgentManager instance.
|
|
7
|
-
* Extends the options available in `HttpAgentOptions`.
|
|
8
|
-
*
|
|
9
|
-
* @extends HttpAgentOptions
|
|
10
|
-
*
|
|
11
|
-
* @property {number} [port] - The port number to be used by the agent.
|
|
12
|
-
* @property {boolean} [withLocalEnv] - Whether to include local environment variables.
|
|
13
|
-
* @property {boolean} [withDevtools] - Whether to enable developer tools integration.
|
|
14
|
-
* @property {boolean} [withProcessEnv] - Whether to include process environment variables.
|
|
15
|
-
* @property {boolean} [initializeOnCreate] - Whether to initialize the agent upon creation.
|
|
16
|
-
*/
|
|
17
|
-
export interface AgentManagerParameters extends HttpAgentOptions {
|
|
18
|
-
port?: number;
|
|
19
|
-
withLocalEnv?: boolean;
|
|
20
|
-
withDevtools?: boolean;
|
|
21
|
-
withProcessEnv?: boolean;
|
|
22
|
-
initializeOnCreate?: boolean;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Represents the state of an agent.
|
|
26
|
-
*/
|
|
27
|
-
export interface AgentState {
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated Use `isInitialized` instead.
|
|
30
|
-
* Indicates whether the agent has been initialized.
|
|
31
|
-
*/
|
|
32
|
-
initialized: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Indicates whether the agent has been initialized.
|
|
35
|
-
*/
|
|
36
|
-
isInitialized: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated Use `isInitializing` instead.
|
|
39
|
-
* Indicates whether the agent is in the process of initializing.
|
|
40
|
-
*/
|
|
41
|
-
initializing: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Indicates whether the agent is in the process of initializing.
|
|
44
|
-
*/
|
|
45
|
-
isInitializing: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Represents an error associated with the agent, if any.
|
|
48
|
-
*/
|
|
49
|
-
error: AgentError | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* Represents the network associated with the agent, if any.
|
|
52
|
-
*/
|
|
53
|
-
network: string | undefined;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Represents the authentication state of an agent.
|
|
57
|
-
*/
|
|
58
|
-
export interface AuthState {
|
|
59
|
-
identity: Identity | null;
|
|
60
|
-
/**
|
|
61
|
-
* @deprecated Use `isAuthenticating` instead.
|
|
62
|
-
* Indicates whether the authentication process is ongoing.
|
|
63
|
-
*/
|
|
64
|
-
authenticating: boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Indicates whether the authentication process is ongoing.
|
|
67
|
-
*/
|
|
68
|
-
isAuthenticating: boolean;
|
|
69
|
-
/**
|
|
70
|
-
* @deprecated Use `isAuthenticated` instead.
|
|
71
|
-
* Indicates whether the agent is authenticated.
|
|
72
|
-
*/
|
|
73
|
-
authenticated: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Indicates whether the agent is authenticated.
|
|
76
|
-
*/
|
|
77
|
-
isAuthenticated: boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Represents any error that occurred during authentication.
|
|
80
|
-
*/
|
|
81
|
-
error: Error | undefined;
|
|
82
|
-
}
|
|
83
|
-
export interface UpdateAgentParameters extends HttpAgentOptions {
|
|
84
|
-
agent?: HttpAgent;
|
|
85
|
-
}
|
|
86
|
-
export type AgentStore = StoreWithAllMiddleware<AgentState>;
|
|
87
|
-
export type AuthStore = StoreWithAllMiddleware<AuthState>;
|
package/dist/classes/index.d.ts
DELETED
package/dist/classes/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./actor"), exports);
|
|
18
|
-
__exportStar(require("./agent"), exports);
|
|
19
|
-
__exportStar(require("./adapter"), exports);
|
package/dist/classes/types.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export * from "./agent/types";
|
|
2
|
-
export * from "./actor/types";
|
|
3
|
-
export * from "./adapter/types";
|
|
4
|
-
import { type StateCreator, type StoreApi, type StoreMutatorIdentifier, type Mutate } from "zustand";
|
|
5
|
-
export type StoreWithMiddleware<T, Mis extends [StoreMutatorIdentifier, unknown][] = [], Mos extends [StoreMutatorIdentifier, unknown][] = []> = StateCreator<T, Mis, Mos>;
|
|
6
|
-
export type StoreApiWithMiddleware<T, Mos extends [StoreMutatorIdentifier, unknown][] = []> = Mutate<StoreApi<T>, Mos>;
|
|
7
|
-
export type WithDevtools = ["zustand/devtools", never];
|
|
8
|
-
export type WithSubscribeSelector = ["zustand/subscribeWithSelector", never];
|
|
9
|
-
export type StoreWithAllMiddleware<T> = StoreApiWithMiddleware<T, [
|
|
10
|
-
WithDevtools,
|
|
11
|
-
WithSubscribeSelector
|
|
12
|
-
]>;
|
|
13
|
-
export type StoreWithSubscribeOnly<T> = StoreApiWithMiddleware<T, [
|
|
14
|
-
WithSubscribeSelector
|
|
15
|
-
]>;
|
package/dist/classes/types.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
// Re-export existing types
|
|
18
|
-
__exportStar(require("./agent/types"), exports);
|
|
19
|
-
__exportStar(require("./actor/types"), exports);
|
|
20
|
-
__exportStar(require("./adapter/types"), exports);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ActorManager } from "./classes/actor";
|
|
2
|
-
import type { 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:268-283
|
|
11
|
-
*/
|
|
12
|
-
export declare const createActorManager: <A = BaseActor>(config: ActorManagerParameters) => ActorManager<A>;
|
|
@@ -1,17 +0,0 @@
|
|
|
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:268-283
|
|
13
|
-
*/
|
|
14
|
-
const createActorManager = (config) => {
|
|
15
|
-
return new actor_1.ActorManager(config);
|
|
16
|
-
};
|
|
17
|
-
exports.createActorManager = createActorManager;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { AgentManager } from "./classes/agent";
|
|
2
|
-
import type { 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:232-260
|
|
11
|
-
*/
|
|
12
|
-
export declare const createAgentManager: (config?: AgentManagerParameters) => AgentManager;
|
|
@@ -1,17 +0,0 @@
|
|
|
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:232-260
|
|
13
|
-
*/
|
|
14
|
-
const createAgentManager = (config) => {
|
|
15
|
-
return new agent_1.AgentManager(config);
|
|
16
|
-
};
|
|
17
|
-
exports.createAgentManager = createAgentManager;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { CandidAdapter } from "./classes/adapter";
|
|
2
|
-
import type { 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:151-192
|
|
10
|
-
*/
|
|
11
|
-
export declare const createCandidAdapter: (config: CandidAdapterParameters) => CandidAdapter;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCandidAdapter = void 0;
|
|
4
|
-
const adapter_1 = require("./classes/adapter");
|
|
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:151-192
|
|
12
|
-
*/
|
|
13
|
-
const createCandidAdapter = (config) => {
|
|
14
|
-
return new adapter_1.CandidAdapter(config);
|
|
15
|
-
};
|
|
16
|
-
exports.createCandidAdapter = createCandidAdapter;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { BaseActor, CreateReactorCoreParameters, CreateReactorCoreReturnType } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* The Core module is the main entry point for the library.
|
|
4
|
-
* Create a new actor manager with the given options.
|
|
5
|
-
* Its create a new agent manager if not provided.
|
|
6
|
-
*
|
|
7
|
-
* @category Main
|
|
8
|
-
* @includeExample ./packages/core/README.md:32-86
|
|
9
|
-
*/
|
|
10
|
-
export declare const createReactorCore: <A = BaseActor>(config: CreateReactorCoreParameters) => CreateReactorCoreReturnType<A>;
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createReactorCore = void 0;
|
|
4
|
-
const createReactorStore_1 = require("./createReactorStore");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
/**
|
|
7
|
-
* The Core module is the main entry point for the library.
|
|
8
|
-
* Create a new actor manager with the given options.
|
|
9
|
-
* Its create a new agent manager if not provided.
|
|
10
|
-
*
|
|
11
|
-
* @category Main
|
|
12
|
-
* @includeExample ./packages/core/README.md:32-86
|
|
13
|
-
*/
|
|
14
|
-
const createReactorCore = (config) => {
|
|
15
|
-
const { subscribeActorState, updateMethodState, callMethodWithOptions, callMethod, getState, agentManager, ...rest } = (0, createReactorStore_1.createReactorStore)(config);
|
|
16
|
-
const actorMethod = (functionName, args, options = {}) => {
|
|
17
|
-
const requestHash = (0, utils_1.generateRequestHash)(args);
|
|
18
|
-
const updateState = (newState = {}) => {
|
|
19
|
-
updateMethodState(functionName, requestHash, newState);
|
|
20
|
-
};
|
|
21
|
-
updateState();
|
|
22
|
-
try {
|
|
23
|
-
const methodState = ((key) => {
|
|
24
|
-
const state = getState().methodState[functionName][requestHash];
|
|
25
|
-
switch (key) {
|
|
26
|
-
case "data":
|
|
27
|
-
return state.data;
|
|
28
|
-
case "loading":
|
|
29
|
-
return state.loading;
|
|
30
|
-
case "error":
|
|
31
|
-
return state.error;
|
|
32
|
-
default:
|
|
33
|
-
return state;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
const subscribe = (callback) => {
|
|
37
|
-
callback(methodState());
|
|
38
|
-
const unsubscribe = subscribeActorState((state) => {
|
|
39
|
-
const methodState = state.methodState[functionName];
|
|
40
|
-
const methodStateHash = methodState[requestHash];
|
|
41
|
-
if (methodStateHash) {
|
|
42
|
-
callback(methodStateHash);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return unsubscribe;
|
|
46
|
-
};
|
|
47
|
-
const call = async (replaceArgs) => {
|
|
48
|
-
updateState({
|
|
49
|
-
loading: true,
|
|
50
|
-
error: undefined,
|
|
51
|
-
});
|
|
52
|
-
try {
|
|
53
|
-
const data = await callMethodWithOptions(options)(functionName, ...(replaceArgs ?? args));
|
|
54
|
-
updateState({ data, loading: false });
|
|
55
|
-
return data;
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
updateState({
|
|
59
|
-
error: error,
|
|
60
|
-
loading: false,
|
|
61
|
-
});
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
return {
|
|
66
|
-
requestHash,
|
|
67
|
-
subscribe,
|
|
68
|
-
getState: methodState,
|
|
69
|
-
call,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
updateState({
|
|
74
|
-
error: error,
|
|
75
|
-
loading: false,
|
|
76
|
-
});
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
const queryCall = ({ functionName, args = [], refetchOnMount = true, refetchInterval = false, ...options }) => {
|
|
81
|
-
let intervalId = null;
|
|
82
|
-
const { call, ...rest } = actorMethod(functionName, args, options);
|
|
83
|
-
if (refetchInterval) {
|
|
84
|
-
intervalId = setInterval(() => {
|
|
85
|
-
call();
|
|
86
|
-
}, refetchInterval);
|
|
87
|
-
}
|
|
88
|
-
const clearRefetchInterval = () => {
|
|
89
|
-
if (intervalId) {
|
|
90
|
-
clearInterval(intervalId);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
let dataPromise = Promise.resolve();
|
|
94
|
-
if (refetchOnMount)
|
|
95
|
-
dataPromise = call();
|
|
96
|
-
return { ...rest, call, dataPromise, intervalId, clearRefetchInterval };
|
|
97
|
-
};
|
|
98
|
-
const updateCall = ({ functionName, args = [], ...options }) => {
|
|
99
|
-
return actorMethod(functionName, args, options);
|
|
100
|
-
};
|
|
101
|
-
return {
|
|
102
|
-
getState,
|
|
103
|
-
queryCall,
|
|
104
|
-
updateCall,
|
|
105
|
-
callMethod,
|
|
106
|
-
callMethodWithOptions,
|
|
107
|
-
subscribeActorState,
|
|
108
|
-
...agentManager,
|
|
109
|
-
...rest,
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
exports.createReactorCore = createReactorCore;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ActorManager } from "./classes/actor";
|
|
2
|
-
import type { BaseActor, CreateReactorStoreParameters } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* Create a new actor manager with the given options.
|
|
5
|
-
* Its create a new agent manager if not provided.
|
|
6
|
-
* It also creates a new actor manager with the given options.
|
|
7
|
-
*
|
|
8
|
-
* @category Main
|
|
9
|
-
* @includeExample ./packages/core/README.md:200-225
|
|
10
|
-
*/
|
|
11
|
-
export declare const createReactorStore: <A = BaseActor>(config: CreateReactorStoreParameters) => ActorManager<A>;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createReactorStore = void 0;
|
|
4
|
-
const createActorManager_1 = require("./createActorManager");
|
|
5
|
-
const createAgentManager_1 = require("./createAgentManager");
|
|
6
|
-
/**
|
|
7
|
-
* Create a new actor manager with the given options.
|
|
8
|
-
* Its create a new agent manager if not provided.
|
|
9
|
-
* It also creates a new actor manager with the given options.
|
|
10
|
-
*
|
|
11
|
-
* @category Main
|
|
12
|
-
* @includeExample ./packages/core/README.md:200-225
|
|
13
|
-
*/
|
|
14
|
-
const createReactorStore = (config) => {
|
|
15
|
-
const { idlFactory, canisterId, withDevtools = false, initializeOnCreate = true, withVisitor = false, agentManager: maybeAgentManager, ...agentParameters } = config;
|
|
16
|
-
const agentManager = maybeAgentManager ||
|
|
17
|
-
(0, createAgentManager_1.createAgentManager)({
|
|
18
|
-
withDevtools,
|
|
19
|
-
...agentParameters,
|
|
20
|
-
});
|
|
21
|
-
const actorManager = (0, createActorManager_1.createActorManager)({
|
|
22
|
-
idlFactory,
|
|
23
|
-
canisterId,
|
|
24
|
-
agentManager,
|
|
25
|
-
withVisitor,
|
|
26
|
-
withDevtools,
|
|
27
|
-
initializeOnCreate,
|
|
28
|
-
});
|
|
29
|
-
return actorManager;
|
|
30
|
-
};
|
|
31
|
-
exports.createReactorStore = createReactorStore;
|