@ic-reactor/candid 3.0.0-beta.0
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 +358 -0
- package/dist/adapter.d.ts +197 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +384 -0
- package/dist/adapter.js.map +1 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +11 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/reactor.d.ts +103 -0
- package/dist/reactor.d.ts.map +1 -0
- package/dist/reactor.js +173 -0
- package/dist/reactor.js.map +1 -0
- package/dist/types.d.ts +77 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +14 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +27 -0
- package/dist/utils.js.map +1 -0
- package/package.json +72 -0
package/dist/reactor.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Reactor } from "@ic-reactor/core";
|
|
2
|
+
import { CandidAdapter } from "./adapter";
|
|
3
|
+
import { IDL } from "@icp-sdk/core/candid";
|
|
4
|
+
export class CandidReactor extends Reactor {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
// If idlFactory/actor are missing, use a dummy one to satisfy Reactor constructor
|
|
7
|
+
const superConfig = { ...config };
|
|
8
|
+
if (!superConfig.idlFactory && !superConfig.actor) {
|
|
9
|
+
superConfig.idlFactory = (config) => config.IDL.Service({});
|
|
10
|
+
}
|
|
11
|
+
super(superConfig);
|
|
12
|
+
Object.defineProperty(this, "adapter", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: void 0
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "candidSource", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: void 0
|
|
23
|
+
});
|
|
24
|
+
this.candidSource = config.candid;
|
|
25
|
+
this.adapter = new CandidAdapter({
|
|
26
|
+
clientManager: this.clientManager,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Initializes the reactor by parsing the provided Candid string or fetching it from the network.
|
|
31
|
+
* This updates the internal service definition with the actual canister interface.
|
|
32
|
+
*
|
|
33
|
+
* After initialization, all standard Reactor methods (callMethod, fetchQuery, etc.) work.
|
|
34
|
+
*/
|
|
35
|
+
async initialize() {
|
|
36
|
+
let idlFactory;
|
|
37
|
+
if (this.candidSource) {
|
|
38
|
+
const definition = await this.adapter.parseCandidSource(this.candidSource);
|
|
39
|
+
idlFactory = definition.idlFactory;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const definition = await this.adapter.getCandidDefinition(this.canisterId);
|
|
43
|
+
idlFactory = definition.idlFactory;
|
|
44
|
+
}
|
|
45
|
+
this.service = idlFactory({ IDL });
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Register a dynamic method by its Candid signature.
|
|
49
|
+
* After registration, all standard Reactor methods work with this method name.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // Register a method
|
|
54
|
+
* await reactor.registerMethod({
|
|
55
|
+
* functionName: "icrc1_balance_of",
|
|
56
|
+
* candid: "(record { owner : principal }) -> (nat) query"
|
|
57
|
+
* })
|
|
58
|
+
*
|
|
59
|
+
* // Now use standard Reactor methods!
|
|
60
|
+
* const balance = await reactor.callMethod({
|
|
61
|
+
* functionName: "icrc1_balance_of",
|
|
62
|
+
* args: [{ owner }]
|
|
63
|
+
* })
|
|
64
|
+
*
|
|
65
|
+
* // Or with caching
|
|
66
|
+
* const cachedBalance = await reactor.fetchQuery({
|
|
67
|
+
* functionName: "icrc1_balance_of",
|
|
68
|
+
* args: [{ owner }]
|
|
69
|
+
* })
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
async registerMethod(options) {
|
|
73
|
+
const { functionName, candid } = options;
|
|
74
|
+
// Check if method already registered
|
|
75
|
+
const existing = this.service._fields.find(([name]) => name === functionName);
|
|
76
|
+
if (existing)
|
|
77
|
+
return;
|
|
78
|
+
// Parse the Candid signature
|
|
79
|
+
const serviceSource = candid.includes("service :")
|
|
80
|
+
? candid
|
|
81
|
+
: `service : { ${functionName} : ${candid}; }`;
|
|
82
|
+
const { idlFactory } = await this.adapter.parseCandidSource(serviceSource);
|
|
83
|
+
const parsedService = idlFactory({ IDL });
|
|
84
|
+
const funcField = parsedService._fields.find(([name]) => name === functionName);
|
|
85
|
+
if (!funcField) {
|
|
86
|
+
throw new Error(`Method "${functionName}" not found in the provided Candid signature`);
|
|
87
|
+
}
|
|
88
|
+
// Inject into our service
|
|
89
|
+
this.service._fields.push(funcField);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Register multiple methods at once.
|
|
93
|
+
*/
|
|
94
|
+
async registerMethods(methods) {
|
|
95
|
+
await Promise.all(methods.map((m) => this.registerMethod(m)));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check if a method is registered (either from initialize or registerMethod).
|
|
99
|
+
*/
|
|
100
|
+
hasMethod(functionName) {
|
|
101
|
+
return this.service._fields.some(([name]) => name === functionName);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get all registered method names.
|
|
105
|
+
*/
|
|
106
|
+
getMethodNames() {
|
|
107
|
+
return this.service._fields.map(([name]) => name);
|
|
108
|
+
}
|
|
109
|
+
// ══════════════════════════════════════════════════════════════════════
|
|
110
|
+
// DYNAMIC CALL SHORTCUTS
|
|
111
|
+
// ══════════════════════════════════════════════════════════════════════
|
|
112
|
+
/**
|
|
113
|
+
* Perform a dynamic update call in one step.
|
|
114
|
+
* Registers the method if not already registered, then calls it.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const result = await reactor.callDynamic({
|
|
119
|
+
* functionName: "transfer",
|
|
120
|
+
* candid: "(record { to : principal; amount : nat }) -> (variant { Ok : nat; Err : text })",
|
|
121
|
+
* args: [{ to: Principal.fromText("..."), amount: 100n }]
|
|
122
|
+
* })
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
async callDynamic(options) {
|
|
126
|
+
await this.registerMethod(options);
|
|
127
|
+
return this.callMethod({
|
|
128
|
+
functionName: options.functionName,
|
|
129
|
+
args: options.args,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Perform a dynamic query call in one step.
|
|
134
|
+
* Registers the method if not already registered, then calls it.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const balance = await reactor.queryDynamic({
|
|
139
|
+
* functionName: "icrc1_balance_of",
|
|
140
|
+
* candid: "(record { owner : principal }) -> (nat) query",
|
|
141
|
+
* args: [{ owner: Principal.fromText("...") }]
|
|
142
|
+
* })
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
async queryDynamic(options) {
|
|
146
|
+
await this.registerMethod(options);
|
|
147
|
+
return this.callMethod({
|
|
148
|
+
functionName: options.functionName,
|
|
149
|
+
args: options.args,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Fetch with dynamic Candid and TanStack Query caching.
|
|
154
|
+
* Registers the method if not already registered, then fetches with caching.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const balance = await reactor.fetchQueryDynamic({
|
|
159
|
+
* functionName: "icrc1_balance_of",
|
|
160
|
+
* candid: "(record { owner : principal }) -> (nat) query",
|
|
161
|
+
* args: [{ owner }]
|
|
162
|
+
* })
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
async fetchQueryDynamic(options) {
|
|
166
|
+
await this.registerMethod(options);
|
|
167
|
+
return this.fetchQuery({
|
|
168
|
+
functionName: options.functionName,
|
|
169
|
+
args: options.args,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=reactor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactor.js","sourceRoot":"","sources":["../src/reactor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAE1C,MAAM,OAAO,aAA6B,SAAQ,OAAU;IAI1D,YAAY,MAAkC;QAC5C,kFAAkF;QAClF,MAAM,WAAW,GAAG,EAAE,GAAG,MAAM,EAAE,CAAA;QAEjC,IAAI,CAAC,WAAW,CAAC,UAAU,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;YAClD,WAAW,CAAC,UAAU,GAAG,CAAC,MAAoB,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QAC3E,CAAC;QAED,KAAK,CAAC,WAAmC,CAAC,CAAA;QAXrC;;;;;WAAsB;QACrB;;;;;WAAqB;QAY3B,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,CAAA;QACjC,IAAI,CAAC,OAAO,GAAG,IAAI,aAAa,CAAC;YAC/B,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC,CAAA;IACJ,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,UAAU;QACrB,IAAI,UAAgC,CAAA;QAEpC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC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D,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;QAClC,OAAO,IAAI,CAAC,UAAU,CAAC;YACrB,YAAY,EAAE,OAAO,CAAC,YAAmB;YACzC,IAAI,EAAE,OAAO,CAAC,IAAW;SAC1B,CAAM,CAAA;IACT,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { HttpAgent, Identity } from "@icp-sdk/core/agent";
|
|
2
|
+
import type { IDL } from "@icp-sdk/core/candid";
|
|
3
|
+
import type { BaseActor, CanisterId, ReactorParameters } from "@ic-reactor/core";
|
|
4
|
+
export interface DynamicMethodOptions {
|
|
5
|
+
/** The method name to register. */
|
|
6
|
+
functionName: string;
|
|
7
|
+
/**
|
|
8
|
+
* The Candid signature for the method.
|
|
9
|
+
* Can be either a method signature like "(text) -> (text) query"
|
|
10
|
+
* or a full service definition like "service : { greet: (text) -> (text) query }".
|
|
11
|
+
*/
|
|
12
|
+
candid: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CandidReactorParameters<A = BaseActor> extends Omit<ReactorParameters<A>, "idlFactory" | "actor"> {
|
|
15
|
+
/** The canister ID. */
|
|
16
|
+
canisterId: CanisterId;
|
|
17
|
+
/** The Candid source code. */
|
|
18
|
+
candid?: string;
|
|
19
|
+
/** The IDL interface factory. */
|
|
20
|
+
idlFactory?: IDL.InterfaceFactory;
|
|
21
|
+
/** The actor instance. */
|
|
22
|
+
actor?: A;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Minimal interface for ClientManager that CandidAdapter depends on.
|
|
26
|
+
* This allows the candid package to work with ClientManager without importing the full core package.
|
|
27
|
+
*/
|
|
28
|
+
export interface CandidClientManager {
|
|
29
|
+
/** The HTTP agent used for making requests. */
|
|
30
|
+
agent: HttpAgent;
|
|
31
|
+
/** Whether the agent is connected to a local network. */
|
|
32
|
+
isLocal: boolean;
|
|
33
|
+
/** Subscribe to identity changes. Returns an unsubscribe function. */
|
|
34
|
+
subscribe(callback: (identity: Identity) => void): () => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parameters for initializing the CandidAdapter.
|
|
38
|
+
*/
|
|
39
|
+
export interface CandidAdapterParameters {
|
|
40
|
+
/** The client manager that provides agent and identity access. */
|
|
41
|
+
clientManager: CandidClientManager;
|
|
42
|
+
/** The canister ID of the didjs canister for compiling Candid to JavaScript. */
|
|
43
|
+
didjsCanisterId?: CanisterId;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Represents a parsed Candid definition with IDL factory and initialization.
|
|
47
|
+
*/
|
|
48
|
+
export interface CandidDefinition {
|
|
49
|
+
/** The IDL interface factory. */
|
|
50
|
+
idlFactory: IDL.InterfaceFactory;
|
|
51
|
+
/** Optional init function for the canister. */
|
|
52
|
+
init?: (args: {
|
|
53
|
+
IDL: typeof IDL;
|
|
54
|
+
}) => IDL.Type<unknown>[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Interface for the optional parser module (@ic-reactor/parser).
|
|
58
|
+
*/
|
|
59
|
+
export interface ReactorParser {
|
|
60
|
+
/**
|
|
61
|
+
* Default function to initialize the WASM module.
|
|
62
|
+
*/
|
|
63
|
+
default?: () => Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Converts Candid (DID) source to JavaScript code.
|
|
66
|
+
* @param candidSource - The Candid source code.
|
|
67
|
+
* @returns The JavaScript code.
|
|
68
|
+
*/
|
|
69
|
+
didToJs(candidSource: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* Validates the Candid (IDL) source.
|
|
72
|
+
* @param candidSource - The Candid source code.
|
|
73
|
+
* @returns True if valid, false otherwise.
|
|
74
|
+
*/
|
|
75
|
+
validateIDL(candidSource: string): boolean;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.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,EAAE;QAAE,GAAG,EAAE,OAAO,GAAG,CAAA;KAAE,KAAK,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAA;CAC1D;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7B;;;;OAIG;IACH,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAA;IACrC;;;;OAIG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAA;CAC3C"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CandidDefinition } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* A no-operation function placeholder.
|
|
4
|
+
*/
|
|
5
|
+
export declare const noop: () => void;
|
|
6
|
+
/**
|
|
7
|
+
* Imports and evaluates a Candid definition from JavaScript code.
|
|
8
|
+
*
|
|
9
|
+
* @param candidJs - The JavaScript code containing the Candid definition.
|
|
10
|
+
* @returns A promise that resolves to the CandidDefinition.
|
|
11
|
+
* @throws Error if the import fails.
|
|
12
|
+
*/
|
|
13
|
+
export declare function importCandidDefinition(candidJs: string): Promise<CandidDefinition>;
|
|
14
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C;;GAEG;AACH,eAAO,MAAM,IAAI,YAAW,CAAA;AAE5B;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,gBAAgB,CAAC,CAgB3B"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A no-operation function placeholder.
|
|
3
|
+
*/
|
|
4
|
+
export const noop = () => { };
|
|
5
|
+
/**
|
|
6
|
+
* Imports and evaluates a Candid definition from JavaScript code.
|
|
7
|
+
*
|
|
8
|
+
* @param candidJs - The JavaScript code containing the Candid definition.
|
|
9
|
+
* @returns A promise that resolves to the CandidDefinition.
|
|
10
|
+
* @throws Error if the import fails.
|
|
11
|
+
*/
|
|
12
|
+
export async function importCandidDefinition(candidJs) {
|
|
13
|
+
try {
|
|
14
|
+
// Create a data URL with the JavaScript code
|
|
15
|
+
const dataUri = "data:text/javascript;charset=utf-8," + encodeURIComponent(candidJs);
|
|
16
|
+
// Dynamically import the module
|
|
17
|
+
const module = await import(/* webpackIgnore: true */ dataUri);
|
|
18
|
+
return {
|
|
19
|
+
idlFactory: module.idlFactory,
|
|
20
|
+
init: module.init,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new Error(`Failed to import Candid definition: ${error}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA;AAE5B;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,QAAgB;IAEhB,IAAI,CAAC;QACH,6CAA6C;QAC7C,MAAM,OAAO,GACX,qCAAqC,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAA;QAEtE,gCAAgC;QAChC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAA;QAE9D,OAAO;YACL,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,uCAAuC,KAAK,EAAE,CAAC,CAAA;IACjE,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ic-reactor/candid",
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
|
+
"description": "IC Reactor Candid Adapter - Fetch and parse Candid definitions from Internet Computer canisters",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "rm -rf dist tsconfig.tsbuildinfo && tsc -b",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"version:sync": "node -e \"const pkg = require('./package.json'); const fs = require('fs'); fs.writeFileSync('./src/version.ts', '/**\\n * Library version - automatically synced from package.json.\\n */\\nexport const VERSION = \\\"' + pkg.version + '\\\"\\n');\"",
|
|
25
|
+
"size": "size-limit",
|
|
26
|
+
"analyze": "size-limit --why"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/B3Pay/ic-reactor",
|
|
31
|
+
"directory": "packages/candid"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/B3Pay/ic-reactor/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://ic-reactor.dev",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"internet-computer",
|
|
39
|
+
"icp",
|
|
40
|
+
"dfinity",
|
|
41
|
+
"candid",
|
|
42
|
+
"web3",
|
|
43
|
+
"blockchain",
|
|
44
|
+
"canister",
|
|
45
|
+
"actor",
|
|
46
|
+
"reactor"
|
|
47
|
+
],
|
|
48
|
+
"author": "Behrad Deylami",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@ic-reactor/core": "workspace:^"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@icp-sdk/core": "^5.0.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@icp-sdk/core": "^5.0.0",
|
|
59
|
+
"@size-limit/preset-small-lib": "^12.0.0",
|
|
60
|
+
"@types/node": "^24.10.1",
|
|
61
|
+
"size-limit": "^12.0.0",
|
|
62
|
+
"vitest": "^4.0.16"
|
|
63
|
+
},
|
|
64
|
+
"size-limit": [
|
|
65
|
+
{
|
|
66
|
+
"name": "Candid Adapter",
|
|
67
|
+
"path": "dist/index.js",
|
|
68
|
+
"limit": "10 KB",
|
|
69
|
+
"gzip": true
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}
|