@ic-reactor/core 1.6.0-beta.5 → 1.6.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import type { ActorMethodParameters, ActorMethodReturnType, ActorStore, ActorManagerParameters, FunctionName, VisitService, BaseActor, ActorMethodState, MethodAttributes } from "./types";
2
2
  import { IDL } from "@dfinity/candid";
3
3
  import type { AgentManager } from "../agent";
4
- import type { UpdateAgentParameters } from "../../types";
4
+ import type { UpdateAgentParameters } from "../types";
5
5
  export declare class ActorManager<A = BaseActor> {
6
6
  private _actor;
7
7
  private _idlFactory;
@@ -1,7 +1,5 @@
1
- import type { IDL } from "@dfinity/candid";
2
1
  import type { AgentManager } from "../agent";
3
- import type { ActorMethod, ActorSubclass, Principal } from "../../types";
4
- import { StoreApiWithDevtools } from "../types";
2
+ import type { IDL, StoreApiWithDevtools, ActorMethod, ActorSubclass, Principal } from "../../types";
5
3
  export interface DefaultActorType {
6
4
  [key: string]: ActorMethod;
7
5
  }
@@ -1,12 +1,12 @@
1
1
  import { HttpAgent } from "@dfinity/agent";
2
- import type { CanisterId, CandidAdapterParameters, CandidDefenition } from "../../types";
2
+ import type { CanisterId, CandidAdapterParameters, CandidDefenition, ReactorParser } from "../../types";
3
3
  export declare class CandidAdapter {
4
4
  agent: HttpAgent;
5
5
  didjsCanisterId: string;
6
6
  private parserModule?;
7
7
  unsubscribeAgent: () => void;
8
8
  constructor({ agentManager, agent, didjsCanisterId, }: CandidAdapterParameters);
9
- initializeParser(): Promise<void>;
9
+ initializeParser(module?: ReactorParser): Promise<void>;
10
10
  private getDefaultDidJsId;
11
11
  getCandidDefinition(canisterId: CanisterId): Promise<CandidDefenition>;
12
12
  getFromMetadata(canisterId: CanisterId): Promise<string | undefined>;
@@ -1,27 +1,4 @@
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -54,11 +31,18 @@ class CandidAdapter {
54
31
  }
55
32
  this.didjsCanisterId = didjsCanisterId || this.getDefaultDidJsId();
56
33
  }
57
- initializeParser() {
34
+ initializeParser(module) {
58
35
  return __awaiter(this, void 0, void 0, function* () {
36
+ if (module !== undefined) {
37
+ this.parserModule = module;
38
+ return;
39
+ }
59
40
  try {
60
- this.parserModule = yield Promise.resolve().then(() => __importStar(require("@ic-reactor/parser")));
61
- yield this.parserModule.default();
41
+ this.parserModule = require("@ic-reactor/parser");
42
+ if (typeof this.parserModule !== "undefined" &&
43
+ "default" in this.parserModule) {
44
+ yield this.parserModule.default();
45
+ }
62
46
  }
63
47
  catch (error) {
64
48
  throw new Error(`Error initializing parser: ${error}`);
@@ -122,6 +106,9 @@ class CandidAdapter {
122
106
  let candidDef = "";
123
107
  try {
124
108
  candidDef = this.parseDidToJs(data);
109
+ if (candidDef === "") {
110
+ throw new Error("Cannot compile Candid to JavaScript");
111
+ }
125
112
  }
126
113
  catch (error) {
127
114
  candidDef = (yield this.fetchDidTojs(data))[0];
@@ -1,4 +1,3 @@
1
- /// <reference path="../../../src/classes/candid/parser.d.ts" />
2
1
  import type { AgentManager } from "../agent";
3
2
  import type { IDL, HttpAgent } from "../../types";
4
3
  export interface CandidAdapterParameters {
@@ -12,3 +11,4 @@ export interface CandidDefenition {
12
11
  idl: typeof IDL;
13
12
  }) => never[];
14
13
  }
14
+ export type ReactorParser = typeof import("@ic-reactor/parser") | typeof import("@ic-reactor/parser/dist/node") | typeof import("@ic-reactor/parser/dist/bundler");
@@ -26,7 +26,7 @@ export declare class AgentManager {
26
26
  getAgent: () => HttpAgent;
27
27
  getAgentHost: () => URL;
28
28
  getIsLocal: () => boolean;
29
- getNetwork: () => "ic" | "local" | "remote";
29
+ getNetwork: () => "local" | "remote" | "ic";
30
30
  getAgentState: AgentStore["getState"];
31
31
  subscribeAgentState: AgentStore["subscribe"];
32
32
  getAuthState: AuthStore["getState"];
@@ -1,6 +1,6 @@
1
1
  import type { HttpAgent, HttpAgentOptions, Identity } from "@dfinity/agent";
2
2
  import type { AuthClient } from "@dfinity/auth-client";
3
- import { StoreApiWithDevtools } from "../types";
3
+ import type { StoreApiWithDevtools } from "../../types";
4
4
  export { HttpAgentOptions, AuthClient, Identity };
5
5
  export interface AgentManagerParameters extends HttpAgentOptions {
6
6
  port?: number;
@@ -1,3 +1,3 @@
1
1
  export * from "./actor";
2
2
  export * from "./agent";
3
- export * from "./candid";
3
+ export * from "./adapter";
@@ -16,4 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./actor"), exports);
18
18
  __exportStar(require("./agent"), exports);
19
- __exportStar(require("./candid"), exports);
19
+ __exportStar(require("./adapter"), exports);
@@ -1,6 +1,6 @@
1
1
  export * from "./agent/types";
2
2
  export * from "./actor/types";
3
- export * from "./candid/types";
3
+ export * from "./adapter/types";
4
4
  import { NamedSet } from "zustand/middleware";
5
5
  import type { StoreApi } from "zustand";
6
6
  export interface StoreApiWithDevtools<T> extends StoreApi<T> {
@@ -16,4 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./agent/types"), exports);
18
18
  __exportStar(require("./actor/types"), exports);
19
- __exportStar(require("./candid/types"), exports);
19
+ __exportStar(require("./adapter/types"), exports);
@@ -1,5 +1,5 @@
1
1
  import { ActorManager } from "./classes/actor";
2
- import { ActorManagerParameters, BaseActor } from "./types";
2
+ import type { ActorManagerParameters, BaseActor } from "./types";
3
3
  /**
4
4
  * Actor manager handles the lifecycle of the actors.
5
5
  * It is responsible for creating and managing the actors.
@@ -1,5 +1,5 @@
1
1
  import { AgentManager } from "./classes/agent";
2
- import { AgentManagerParameters } from "./types";
2
+ import type { AgentManagerParameters } from "./types";
3
3
  /**
4
4
  * Agent manager handles the lifecycle of the `@dfinity/agent`.
5
5
  * It is responsible for creating agent and managing the agent's state.
@@ -1,5 +1,5 @@
1
- import { CandidAdapter } from "./classes/candid";
2
- import { CandidAdapterParameters } from "./types";
1
+ import { CandidAdapter } from "./classes/adapter";
2
+ import type { CandidAdapterParameters } from "./types";
3
3
  /**
4
4
  * The `CandidAdapter` class is used to interact with a canister and retrieve its Candid interface definition.
5
5
  * It provides methods to fetch the Candid definition either from the canister's metadata or by using a temporary hack method.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCandidAdapter = void 0;
4
- const candid_1 = require("./classes/candid");
4
+ const adapter_1 = require("./classes/adapter");
5
5
  /**
6
6
  * The `CandidAdapter` class is used to interact with a canister and retrieve its Candid interface definition.
7
7
  * It provides methods to fetch the Candid definition either from the canister's metadata or by using a temporary hack method.
@@ -11,6 +11,6 @@ const candid_1 = require("./classes/candid");
11
11
  * @includeExample ./packages/core/README.md:151-192
12
12
  */
13
13
  const createCandidAdapter = (config) => {
14
- return new candid_1.CandidAdapter(config);
14
+ return new adapter_1.CandidAdapter(config);
15
15
  };
16
16
  exports.createCandidAdapter = createCandidAdapter;
@@ -21,8 +21,8 @@ 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 utils_1 = require("./utils");
25
24
  const createReactorStore_1 = require("./createReactorStore");
25
+ const utils_1 = require("./utils");
26
26
  /**
27
27
  * The Core module is the main entry point for the library.
28
28
  * Create a new actor manager with the given options.
package/dist/types.d.ts CHANGED
@@ -7,8 +7,7 @@ import type { ActorManager } from "./classes/actor";
7
7
  import type { AgentManager } from "./classes/agent";
8
8
  import type { AuthClientLoginOptions } from "@dfinity/auth-client";
9
9
  export * from "./classes/types";
10
- export type { ActorManager, AgentManager };
11
- export type { ActorMethod, AuthClientLoginOptions, HttpAgentOptions, ActorSubclass, Principal, HttpAgent, Identity, IDL, };
10
+ export type { ActorManager, AgentManager, ActorMethod, AuthClientLoginOptions, HttpAgentOptions, ActorSubclass, Principal, HttpAgent, Identity, IDL, };
12
11
  export interface CreateReactorStoreParameters extends HttpAgentOptions, Omit<ActorManagerParameters, "agentManager"> {
13
12
  agentManager?: AgentManager;
14
13
  withProcessEnv?: boolean;
@@ -0,0 +1 @@
1
+ export * from "@dfinity/agent";
@@ -0,0 +1,17 @@
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("@dfinity/agent"), exports);
@@ -0,0 +1 @@
1
+ export * from "@dfinity/candid";
@@ -0,0 +1,17 @@
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("@dfinity/candid"), exports);
@@ -1,4 +1,5 @@
1
1
  export * from "./helper";
2
2
  export * from "./constants";
3
- export { IDL } from "@dfinity/candid";
4
- export { Principal } from "@dfinity/principal";
3
+ export * as candid from "./candid";
4
+ export * as principal from "./principal";
5
+ export * as agent from "./agent";
@@ -10,14 +10,29 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
13
18
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
20
  };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
16
28
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Principal = exports.IDL = void 0;
29
+ exports.agent = exports.principal = exports.candid = void 0;
18
30
  __exportStar(require("./helper"), exports);
19
31
  __exportStar(require("./constants"), exports);
20
- var candid_1 = require("@dfinity/candid");
21
- Object.defineProperty(exports, "IDL", { enumerable: true, get: function () { return candid_1.IDL; } });
22
- var principal_1 = require("@dfinity/principal");
23
- Object.defineProperty(exports, "Principal", { enumerable: true, get: function () { return principal_1.Principal; } });
32
+ // Re-export the peerDependencies
33
+ /// https://agent-js.icp.xyz/candid
34
+ exports.candid = __importStar(require("./candid"));
35
+ /// https://agent-js.icp.xyz/principal
36
+ exports.principal = __importStar(require("./principal"));
37
+ /// https://agent-js.icp.xyz/agent
38
+ exports.agent = __importStar(require("./agent"));
@@ -0,0 +1 @@
1
+ export * from "@dfinity/principal";
@@ -0,0 +1,17 @@
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("@dfinity/principal"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/core",
3
- "version": "1.6.0-beta.5",
3
+ "version": "1.6.0-beta.7",
4
4
  "description": "A library for intracting with the Internet Computer canisters",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -41,22 +41,20 @@
41
41
  "zustand": "^4.5"
42
42
  },
43
43
  "devDependencies": {
44
- "@ic-reactor/parser": "^0.1.0-beta.1",
45
- "@types/copyfiles": "^2",
46
- "copyfiles": "^2.4.1"
44
+ "@ic-reactor/parser": "^0.1.0-beta.2"
47
45
  },
48
46
  "scripts": {
49
- "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest",
47
+ "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest",
50
48
  "start": "tsc watch",
51
- "bundle": "npm run bundle:dev && npm run bundle:prod",
52
- "bundle:dev": "npx webpack --mode development",
53
- "bundle:prod": "npx webpack --mode production",
54
- "build": "npx tsc && npm run bundle && npm run copy",
55
- "copy": "copyfiles -u 1 \"src/**/*.d.ts\" dist",
49
+ "bundle": "yarn bundle:dev && yarn bundle:prod",
50
+ "bundle:dev": "npx webpack-cli --mode development",
51
+ "bundle:prod": "npx webpack-cli --mode production",
52
+ "build:tsc": "tsc",
53
+ "build": "yarn build:tsc && yarn bundle",
56
54
  "clean": "npx rimraf dist && npx rimraf umd && npx rimraf node_modules"
57
55
  },
58
56
  "engines": {
59
57
  "node": ">=10"
60
58
  },
61
- "gitHead": "bdc3c8204b4950fbbd180c98bf28a50523d0a0a2"
59
+ "gitHead": "970609e4e07d49e34894eaa9ea258ef02390aea1"
62
60
  }
@@ -1,48 +0,0 @@
1
- declare module '@ic-reactor/parser' {
2
- /* tslint:disable */
3
- /* eslint-disable */
4
- /**
5
- * @param {string} prog
6
- * @returns {string}
7
- */
8
- export function did_to_js(prog: string): string;
9
- /**
10
- * @param {string} prog
11
- * @returns {string}
12
- */
13
- export function did_to_ts(prog: string): string;
14
-
15
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
16
-
17
- export interface InitOutput {
18
- readonly memory: WebAssembly.Memory;
19
- readonly did_to_js: (a: number, b: number, c: number) => void;
20
- readonly did_to_ts: (a: number, b: number, c: number) => void;
21
- readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
22
- readonly __wbindgen_malloc: (a: number, b: number) => number;
23
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
24
- readonly __wbindgen_free: (a: number, b: number, c: number) => void;
25
- }
26
-
27
- export type SyncInitInput = BufferSource | WebAssembly.Module;
28
- /**
29
- * Instantiates the given `module`, which can either be bytes or
30
- * a precompiled `WebAssembly.Module`.
31
- *
32
- * @param {SyncInitInput} module
33
- *
34
- * @returns {InitOutput}
35
- */
36
- export function initSync(module: SyncInitInput): InitOutput;
37
-
38
- /**
39
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
40
- * for everything else, calls `WebAssembly.instantiate` directly.
41
- *
42
- * @param {InitInput | Promise<InitInput>} module_or_path
43
- *
44
- * @returns {Promise<InitOutput>}
45
- */
46
- export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
47
-
48
- }
File without changes