@ic-reactor/core 2.0.0-alpha.0 → 2.0.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/README.md +1 -1
- package/dist/classes/actor/index.d.ts +2 -5
- package/dist/classes/actor/index.js +202 -139
- package/dist/classes/actor/types.d.ts +61 -5
- package/dist/classes/adapter/index.d.ts +1 -1
- package/dist/classes/adapter/index.js +80 -101
- package/dist/classes/agent/index.d.ts +5 -7
- package/dist/classes/agent/index.js +189 -183
- package/dist/classes/agent/types.d.ts +66 -6
- package/dist/classes/types.d.ts +12 -5
- package/dist/classes/types.js +1 -0
- package/dist/createReactorCore.js +14 -32
- package/dist/createReactorStore.js +5 -13
- package/dist/index.js +17 -7
- package/dist/types.d.ts +42 -3
- package/dist/utils/constants.d.ts +0 -8
- package/dist/utils/constants.js +1 -9
- package/dist/utils/hash.d.ts +12 -0
- package/dist/utils/hash.js +70 -0
- package/dist/utils/helper.d.ts +54 -6
- package/dist/utils/helper.js +139 -40
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +18 -7
- package/package.json +25 -25
|
@@ -1,27 +1,87 @@
|
|
|
1
|
-
import type { HttpAgent, HttpAgentOptions, Identity } from "@dfinity/agent";
|
|
1
|
+
import type { AgentError, HttpAgent, HttpAgentOptions, Identity } from "@dfinity/agent";
|
|
2
2
|
import type { AuthClient } from "@dfinity/auth-client";
|
|
3
|
-
import type {
|
|
3
|
+
import type { StoreWithAllMiddleware } from "../../types";
|
|
4
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
|
+
*/
|
|
5
17
|
export interface AgentManagerParameters extends HttpAgentOptions {
|
|
6
18
|
port?: number;
|
|
7
19
|
withLocalEnv?: boolean;
|
|
8
20
|
withDevtools?: boolean;
|
|
9
21
|
withProcessEnv?: boolean;
|
|
22
|
+
initializeOnCreate?: boolean;
|
|
10
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Represents the state of an agent.
|
|
26
|
+
*/
|
|
11
27
|
export interface AgentState {
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use `isInitialized` instead.
|
|
30
|
+
* Indicates whether the agent has been initialized.
|
|
31
|
+
*/
|
|
12
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
|
+
*/
|
|
13
41
|
initializing: boolean;
|
|
14
|
-
|
|
15
|
-
|
|
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;
|
|
16
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Represents the authentication state of an agent.
|
|
57
|
+
*/
|
|
17
58
|
export interface AuthState {
|
|
18
59
|
identity: Identity | null;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use `isAuthenticating` instead.
|
|
62
|
+
* Indicates whether the authentication process is ongoing.
|
|
63
|
+
*/
|
|
19
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
|
+
*/
|
|
20
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
|
+
*/
|
|
21
81
|
error: Error | undefined;
|
|
22
82
|
}
|
|
23
83
|
export interface UpdateAgentParameters extends HttpAgentOptions {
|
|
24
84
|
agent?: HttpAgent;
|
|
25
85
|
}
|
|
26
|
-
export type AgentStore =
|
|
27
|
-
export type AuthStore =
|
|
86
|
+
export type AgentStore = StoreWithAllMiddleware<AgentState>;
|
|
87
|
+
export type AuthStore = StoreWithAllMiddleware<AuthState>;
|
package/dist/classes/types.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
export * from "./agent/types";
|
|
2
2
|
export * from "./actor/types";
|
|
3
3
|
export * from "./adapter/types";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
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
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Re-export existing types
|
|
17
18
|
__exportStar(require("./agent/types"), exports);
|
|
18
19
|
__exportStar(require("./actor/types"), exports);
|
|
19
20
|
__exportStar(require("./adapter/types"), exports);
|
|
@@ -1,24 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
3
|
exports.createReactorCore = void 0;
|
|
24
4
|
const createReactorStore_1 = require("./createReactorStore");
|
|
@@ -32,7 +12,7 @@ const utils_1 = require("./utils");
|
|
|
32
12
|
* @includeExample ./packages/core/README.md:32-86
|
|
33
13
|
*/
|
|
34
14
|
const createReactorCore = (config) => {
|
|
35
|
-
const
|
|
15
|
+
const { subscribeActorState, updateMethodState, callMethodWithOptions, callMethod, getState, agentManager, ...rest } = (0, createReactorStore_1.createReactorStore)(config);
|
|
36
16
|
const actorMethod = (functionName, args, options = {}) => {
|
|
37
17
|
const requestHash = (0, utils_1.generateRequestHash)(args);
|
|
38
18
|
const updateState = (newState = {}) => {
|
|
@@ -64,13 +44,13 @@ const createReactorCore = (config) => {
|
|
|
64
44
|
});
|
|
65
45
|
return unsubscribe;
|
|
66
46
|
};
|
|
67
|
-
const call = (replaceArgs) =>
|
|
47
|
+
const call = async (replaceArgs) => {
|
|
68
48
|
updateState({
|
|
69
49
|
loading: true,
|
|
70
50
|
error: undefined,
|
|
71
51
|
});
|
|
72
52
|
try {
|
|
73
|
-
const data =
|
|
53
|
+
const data = await callMethodWithOptions(options)(functionName, ...(replaceArgs ?? args));
|
|
74
54
|
updateState({ data, loading: false });
|
|
75
55
|
return data;
|
|
76
56
|
}
|
|
@@ -81,7 +61,7 @@ const createReactorCore = (config) => {
|
|
|
81
61
|
});
|
|
82
62
|
throw error;
|
|
83
63
|
}
|
|
84
|
-
}
|
|
64
|
+
};
|
|
85
65
|
return {
|
|
86
66
|
requestHash,
|
|
87
67
|
subscribe,
|
|
@@ -97,10 +77,9 @@ const createReactorCore = (config) => {
|
|
|
97
77
|
throw error;
|
|
98
78
|
}
|
|
99
79
|
};
|
|
100
|
-
const queryCall = (
|
|
101
|
-
var { functionName, args = [], refetchOnMount = true, refetchInterval = false } = _a, options = __rest(_a, ["functionName", "args", "refetchOnMount", "refetchInterval"]);
|
|
80
|
+
const queryCall = ({ functionName, args = [], refetchOnMount = true, refetchInterval = false, ...options }) => {
|
|
102
81
|
let intervalId = null;
|
|
103
|
-
const
|
|
82
|
+
const { call, ...rest } = actorMethod(functionName, args, options);
|
|
104
83
|
if (refetchInterval) {
|
|
105
84
|
intervalId = setInterval(() => {
|
|
106
85
|
call();
|
|
@@ -114,17 +93,20 @@ const createReactorCore = (config) => {
|
|
|
114
93
|
let dataPromise = Promise.resolve();
|
|
115
94
|
if (refetchOnMount)
|
|
116
95
|
dataPromise = call();
|
|
117
|
-
return
|
|
96
|
+
return { ...rest, call, dataPromise, intervalId, clearRefetchInterval };
|
|
118
97
|
};
|
|
119
|
-
const updateCall = (
|
|
120
|
-
var { functionName, args = [] } = _a, options = __rest(_a, ["functionName", "args"]);
|
|
98
|
+
const updateCall = ({ functionName, args = [], ...options }) => {
|
|
121
99
|
return actorMethod(functionName, args, options);
|
|
122
100
|
};
|
|
123
|
-
return
|
|
101
|
+
return {
|
|
102
|
+
getState,
|
|
124
103
|
queryCall,
|
|
125
104
|
updateCall,
|
|
126
105
|
callMethod,
|
|
127
106
|
callMethodWithOptions,
|
|
128
|
-
subscribeActorState
|
|
107
|
+
subscribeActorState,
|
|
108
|
+
...agentManager,
|
|
109
|
+
...rest,
|
|
110
|
+
};
|
|
129
111
|
};
|
|
130
112
|
exports.createReactorCore = createReactorCore;
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.createReactorStore = void 0;
|
|
15
4
|
const createActorManager_1 = require("./createActorManager");
|
|
@@ -23,9 +12,12 @@ const createAgentManager_1 = require("./createAgentManager");
|
|
|
23
12
|
* @includeExample ./packages/core/README.md:200-225
|
|
24
13
|
*/
|
|
25
14
|
const createReactorStore = (config) => {
|
|
26
|
-
const { idlFactory, canisterId, withDevtools = false, initializeOnCreate = true, withVisitor = false, agentManager: maybeAgentManager
|
|
15
|
+
const { idlFactory, canisterId, withDevtools = false, initializeOnCreate = true, withVisitor = false, agentManager: maybeAgentManager, ...agentParameters } = config;
|
|
27
16
|
const agentManager = maybeAgentManager ||
|
|
28
|
-
(0, createAgentManager_1.createAgentManager)(
|
|
17
|
+
(0, createAgentManager_1.createAgentManager)({
|
|
18
|
+
withDevtools,
|
|
19
|
+
...agentParameters,
|
|
20
|
+
});
|
|
29
21
|
const actorManager = (0, createActorManager_1.createActorManager)({
|
|
30
22
|
idlFactory,
|
|
31
23
|
canisterId,
|
package/dist/index.js
CHANGED
|
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
18
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
20
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
39
|
exports.utils = exports.types = exports.classes = void 0;
|
|
30
40
|
__exportStar(require("./createReactorCore"), exports);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { ActorMethod, ActorSubclass, HttpAgentOptions, HttpAgent, Identity, CallConfig } from "@dfinity/agent";
|
|
3
2
|
import type { Principal } from "@dfinity/principal";
|
|
4
3
|
import type { IDL } from "@dfinity/candid";
|
|
@@ -49,9 +48,49 @@ export interface ActorUpdateParameters<A, M extends FunctionName<A>> extends Cal
|
|
|
49
48
|
export type ActorMethodCall<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(functionName: M, args: ActorMethodParameters<A[M]>, options?: CallConfig) => ActorUpdateReturnType<A, M>;
|
|
50
49
|
export type ActorQuery<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(params: ActorQueryParameters<A, M>) => ActorQueryReturnType<A, M>;
|
|
51
50
|
export type ActorUpdate<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(params: ActorUpdateParameters<A, M>) => ActorUpdateReturnType<A, M>;
|
|
52
|
-
export
|
|
53
|
-
}
|
|
51
|
+
export type CreateReactorCoreParameters = CreateReactorStoreParameters;
|
|
54
52
|
export interface CreateReactorCoreReturnType<A = BaseActor> extends AgentManager, Omit<ActorManager<A>, "updateMethodState"> {
|
|
55
53
|
queryCall: ActorQuery<A>;
|
|
56
54
|
updateCall: ActorUpdate<A>;
|
|
57
55
|
}
|
|
56
|
+
export type UnwrapResult<T> = T extends {
|
|
57
|
+
Ok: infer U;
|
|
58
|
+
} ? U : T extends {
|
|
59
|
+
Err: infer E;
|
|
60
|
+
} ? E : T;
|
|
61
|
+
type ExtractOkErr<T> = T extends {
|
|
62
|
+
Ok: infer U;
|
|
63
|
+
} ? {
|
|
64
|
+
OkType: U;
|
|
65
|
+
ErrType: never;
|
|
66
|
+
} : T extends {
|
|
67
|
+
Err: infer E;
|
|
68
|
+
} ? {
|
|
69
|
+
OkType: never;
|
|
70
|
+
ErrType: E;
|
|
71
|
+
} : {
|
|
72
|
+
OkType: T;
|
|
73
|
+
ErrType: never;
|
|
74
|
+
};
|
|
75
|
+
export type ExtractOk<T> = T extends {
|
|
76
|
+
Ok: infer U;
|
|
77
|
+
} ? U : never;
|
|
78
|
+
export type ExtractErr<T> = T extends {
|
|
79
|
+
Err: infer E;
|
|
80
|
+
} ? E : never;
|
|
81
|
+
export type CompiledOkResult<U> = {
|
|
82
|
+
isOk: true;
|
|
83
|
+
isErr: false;
|
|
84
|
+
value: U;
|
|
85
|
+
error: null;
|
|
86
|
+
};
|
|
87
|
+
export type CompiledErrResult<E> = {
|
|
88
|
+
isOk: false;
|
|
89
|
+
isErr: true;
|
|
90
|
+
value: null;
|
|
91
|
+
error: E;
|
|
92
|
+
};
|
|
93
|
+
export type CompiledResult<T> = ExtractOkErr<T> extends {
|
|
94
|
+
OkType: infer U;
|
|
95
|
+
ErrType: infer E;
|
|
96
|
+
} ? CompiledOkResult<U> | CompiledErrResult<E> : never;
|
|
@@ -6,11 +6,3 @@ export declare const DEFAULT_LOCAL_DIDJS_ID = "bd3sg-teaaa-aaaaa-qaaba-cai";
|
|
|
6
6
|
export declare const DEFAULT_IC_DIDJS_ID = "a4gq6-oaaaa-aaaab-qaa4q-cai";
|
|
7
7
|
export declare const IC_INTERNET_IDENTITY_PROVIDER = "https://identity.ic0.app/#authorize";
|
|
8
8
|
export declare const LOCAL_INTERNET_IDENTITY_PROVIDER = "http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943/#authorize";
|
|
9
|
-
export declare const ACTOR_INITIAL_STATE: {
|
|
10
|
-
name: string;
|
|
11
|
-
version: number;
|
|
12
|
-
methodState: {};
|
|
13
|
-
initializing: boolean;
|
|
14
|
-
initialized: boolean;
|
|
15
|
-
error: undefined;
|
|
16
|
-
};
|
package/dist/utils/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.LOCAL_INTERNET_IDENTITY_PROVIDER = exports.IC_INTERNET_IDENTITY_PROVIDER = exports.DEFAULT_IC_DIDJS_ID = exports.DEFAULT_LOCAL_DIDJS_ID = exports.LOCAL_HOST_NETWORK_URI = exports.IC_HOST_NETWORK_URI = exports.LOCAL_HOSTS = exports.REMOTE_HOSTS = void 0;
|
|
4
4
|
exports.REMOTE_HOSTS = [".github.dev", ".gitpod.io"];
|
|
5
5
|
exports.LOCAL_HOSTS = ["localhost", "127.0.0.1"];
|
|
6
6
|
exports.IC_HOST_NETWORK_URI = "https://ic0.app";
|
|
@@ -9,11 +9,3 @@ exports.DEFAULT_LOCAL_DIDJS_ID = "bd3sg-teaaa-aaaaa-qaaba-cai";
|
|
|
9
9
|
exports.DEFAULT_IC_DIDJS_ID = "a4gq6-oaaaa-aaaab-qaa4q-cai";
|
|
10
10
|
exports.IC_INTERNET_IDENTITY_PROVIDER = "https://identity.ic0.app/#authorize";
|
|
11
11
|
exports.LOCAL_INTERNET_IDENTITY_PROVIDER = "http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943/#authorize";
|
|
12
|
-
exports.ACTOR_INITIAL_STATE = {
|
|
13
|
-
name: "",
|
|
14
|
-
version: 0,
|
|
15
|
-
methodState: {},
|
|
16
|
-
initializing: false,
|
|
17
|
-
initialized: false,
|
|
18
|
-
error: undefined,
|
|
19
|
-
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a stable string representation of any JavaScript value
|
|
3
|
+
* Handles circular references and maintains consistent object key ordering
|
|
4
|
+
*/
|
|
5
|
+
export declare function stringifyStable(value: unknown): string;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a simple numeric hash code and returns it as a hex string
|
|
8
|
+
* @param value - Any JavaScript value
|
|
9
|
+
* @param length - Desired length of the hex string (default: 8)
|
|
10
|
+
* @returns string - Hex string of specified length
|
|
11
|
+
*/
|
|
12
|
+
export declare function createSimpleHash(value: unknown, length?: number): string;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringifyStable = stringifyStable;
|
|
4
|
+
exports.createSimpleHash = createSimpleHash;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a stable string representation of any JavaScript value
|
|
7
|
+
* Handles circular references and maintains consistent object key ordering
|
|
8
|
+
*/
|
|
9
|
+
function stringifyStable(value) {
|
|
10
|
+
const seen = new WeakSet();
|
|
11
|
+
return JSON.stringify(value, (_, value) => {
|
|
12
|
+
if (value === undefined)
|
|
13
|
+
return "[undefined]";
|
|
14
|
+
if (value === null)
|
|
15
|
+
return "[null]";
|
|
16
|
+
if (Number.isNaN(value))
|
|
17
|
+
return "[NaN]";
|
|
18
|
+
if (value === Infinity)
|
|
19
|
+
return "[Infinity]";
|
|
20
|
+
if (value === -Infinity)
|
|
21
|
+
return "[-Infinity]";
|
|
22
|
+
if (typeof value === "bigint")
|
|
23
|
+
return value.toString();
|
|
24
|
+
if (typeof value === "function")
|
|
25
|
+
return value.toString();
|
|
26
|
+
if (value instanceof Date)
|
|
27
|
+
return value.toISOString();
|
|
28
|
+
if (value instanceof RegExp)
|
|
29
|
+
return value.toString();
|
|
30
|
+
if (ArrayBuffer.isView(value)) {
|
|
31
|
+
return Array.from(value).join(",");
|
|
32
|
+
}
|
|
33
|
+
if (typeof value === "object" && value !== null) {
|
|
34
|
+
if (seen.has(value))
|
|
35
|
+
return "[Circular]";
|
|
36
|
+
seen.add(value);
|
|
37
|
+
if (Array.isArray(value)) {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
const sortedObj = {};
|
|
41
|
+
const sortedKeys = Object.keys(value).sort();
|
|
42
|
+
for (const key of sortedKeys) {
|
|
43
|
+
sortedObj[key] = value[key];
|
|
44
|
+
}
|
|
45
|
+
return sortedObj;
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a simple numeric hash code and returns it as a hex string
|
|
52
|
+
* @param value - Any JavaScript value
|
|
53
|
+
* @param length - Desired length of the hex string (default: 8)
|
|
54
|
+
* @returns string - Hex string of specified length
|
|
55
|
+
*/
|
|
56
|
+
function createSimpleHash(value, length = 8) {
|
|
57
|
+
const str = stringifyStable(value);
|
|
58
|
+
let hash = 0;
|
|
59
|
+
// Generate a more distributed hash
|
|
60
|
+
for (let i = 0; i < str.length; i++) {
|
|
61
|
+
const char = str.charCodeAt(i);
|
|
62
|
+
hash = (hash << 5) - hash + char;
|
|
63
|
+
hash = hash & hash; // Convert to 32-bit integer
|
|
64
|
+
}
|
|
65
|
+
// Convert to positive hex string and ensure proper length
|
|
66
|
+
const positiveHash = Math.abs(hash);
|
|
67
|
+
const hexString = positiveHash.toString(16);
|
|
68
|
+
// Pad with zeros to match desired length
|
|
69
|
+
return hexString.padStart(length, "0");
|
|
70
|
+
}
|
package/dist/utils/helper.d.ts
CHANGED
|
@@ -1,16 +1,64 @@
|
|
|
1
1
|
import { DevtoolsOptions } from "zustand/middleware";
|
|
2
|
-
import type { BaseActor, CandidDefenition, IDL } from "../types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import type { CompiledResult, BaseActor, CandidDefenition, IDL, ExtractOk, StoreWithAllMiddleware } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* No operation function that does nothing.
|
|
5
|
+
* It can be used as a placeholder or for logging purposes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function noop(): void;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a Zustand store with optional DevTools middleware.
|
|
10
|
+
*
|
|
11
|
+
* @param initialState - The initial state of the store.
|
|
12
|
+
* @param config - Configuration options for DevTools.
|
|
13
|
+
* @returns A Zustand store with DevTools enabled if configured, otherwise a standard store.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createStoreWithOptionalDevtools<T extends object>(initialState: T, config: DevtoolsOptions & {
|
|
16
|
+
withDevtools?: boolean;
|
|
17
|
+
}): StoreWithAllMiddleware<T>;
|
|
8
18
|
export declare const importCandidDefinition: (candidDef: string) => Promise<CandidDefenition>;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if the current environment is local or development.
|
|
21
|
+
*
|
|
22
|
+
* @returns `true` if running in a local or development environment, otherwise `false`.
|
|
23
|
+
*/
|
|
9
24
|
export declare const isInLocalOrDevelopment: () => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the network from the process environment variables.
|
|
27
|
+
*
|
|
28
|
+
* @returns The network name, defaulting to "ic" if not specified.
|
|
29
|
+
*/
|
|
10
30
|
export declare const getProcessEnvNetwork: () => string;
|
|
31
|
+
/**
|
|
32
|
+
* Determines the network type based on the provided hostname.
|
|
33
|
+
*
|
|
34
|
+
* @param hostname - The hostname to evaluate.
|
|
35
|
+
* @returns A string indicating the network type: "local", "remote", or "ic".
|
|
36
|
+
*/
|
|
37
|
+
export declare function getNetworkByHostname(hostname: string): "local" | "remote" | "ic";
|
|
38
|
+
/**
|
|
39
|
+
* Checks if a given IDL function is a query.
|
|
40
|
+
*
|
|
41
|
+
* @param func - The IDL function to check.
|
|
42
|
+
* @returns `true` if the function is a query or composite query, otherwise `false`.
|
|
43
|
+
*/
|
|
11
44
|
export declare function isQuery(func: IDL.FuncClass): boolean;
|
|
12
45
|
export declare const jsonToString: (json: unknown, space?: number) => string;
|
|
13
46
|
export declare const generateRequestHash: (args?: unknown[]) => `0x${string}`;
|
|
14
47
|
export declare const generateHash: (field?: unknown) => `0x${string}`;
|
|
15
48
|
export declare const generateActorHash: (actor: BaseActor) => `0x${string}`;
|
|
16
49
|
export declare const stringToHash: (str: string) => `0x${string}`;
|
|
50
|
+
/**
|
|
51
|
+
* Helper function for extracting the value from a compiled result { Ok: T } or { Err: E }
|
|
52
|
+
*
|
|
53
|
+
* @param result - The compiled result to extract from.
|
|
54
|
+
* @returns A `CompiledResult` object indicating success or failure.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createCompiledResult<T>(result: T): CompiledResult<T>;
|
|
57
|
+
/**
|
|
58
|
+
* Helper function for extracting the value from a compiled result { Ok: T } or throw the error if { Err: E }
|
|
59
|
+
*
|
|
60
|
+
* @param result - The compiled result to extract from.
|
|
61
|
+
* @returns The extracted value from the compiled result.
|
|
62
|
+
* @throws The error from the compiled result.
|
|
63
|
+
*/
|
|
64
|
+
export declare function extractOkResult<T>(result: T): ExtractOk<T>;
|