@eosrio/node-abieos 3.3.4-a9d3362 → 4.0.1-2039717

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 CHANGED
@@ -6,8 +6,8 @@
6
6
 
7
7
  Node.js native binding for [abieos](https://github.com/AntelopeIO/abieos), with some improvements:
8
8
 
9
- - Contracts can be directly updated on the map
10
- - Added `abieos_delete_contract`
9
+ - Internal loaded contract map
10
+ - deleteContract: to remove the loaded contract from memory (now in vanilla abieos too)
11
11
 
12
12
  Made with ♥ by [EOS Rio](https://eosrio.io/)
13
13
 
@@ -57,3 +57,9 @@ npm install
57
57
  npm run build:linux
58
58
  npm run build
59
59
  ```
60
+
61
+ ### Documentation
62
+
63
+ For detailed and user-friendly documentation, including installation, usage, API reference, error handling, debugging, and examples, please refer to the [documentation](docs/README.md).
64
+
65
+ For contribution guidelines and developer documentation, refer to the [contribution guidelines](docs/CONTRIBUTING.md).
@@ -1,19 +1,105 @@
1
- export declare class Abieos {
2
- private static instance;
3
- static native: typeof abieos;
4
- private constructor();
5
- static getInstance(): Abieos;
6
- stringToName(nameString: string): BigInteger;
7
- jsonToHex(contractName: string, type: string, json: string | object): string;
8
- hexToJson(contractName: string, type: string, hex: string): any;
9
- binToJson(contractName: string, type: string, buffer: Buffer): any;
10
- loadAbi(contractName: string, abi: string | object): boolean;
11
- loadAbiHex(contractName: string, abihex: string): boolean;
12
- getTypeForAction(contractName: string, actionName: string): string;
13
- getTypeForTable(contractName: string, table_name: string): string;
14
- deleteContract(contractName: string): boolean;
15
- }
16
-
17
- declare const abieos: any;
18
-
19
- export { }
1
+ /**
2
+ * Abieos class provides a singleton instance for interacting with the native abieos module.
3
+ * This pattern is used to ensure a single global context for the underlying C++ abieos library,
4
+ * which manages internal state and resources.
5
+ */
6
+ export declare class Abieos {
7
+ static logTag: string;
8
+ private static instance;
9
+ static native: typeof abieos;
10
+ private static loadedContracts;
11
+ static debug: boolean;
12
+ /**
13
+ * Private constructor to enforce the Singleton pattern.
14
+ * Throws an error if an attempt is made to create a second instance.
15
+ */
16
+ private constructor();
17
+ /**
18
+ * Returns the singleton instance of the Abieos class.
19
+ * If an instance does not already exist, it creates one.
20
+ * @returns {Abieos} The singleton instance of Abieos.
21
+ */
22
+ static getInstance(): Abieos;
23
+ getLoadedAbis(): string[];
24
+ /**
25
+ * Cleans up all loaded contracts by deleting them from the native context.
26
+ * This is useful for freeing up resources and ensuring a clean state.
27
+ */
28
+ cleanup(): void;
29
+ /**
30
+ * Converts a string name to its corresponding 64-bit unsigned integer representation (BigInt).
31
+ * @param {string} nameString The string name to convert.
32
+ * @returns {BigInt} The BigInt representation of the name.
33
+ */
34
+ stringToName(nameString: string): BigInt;
35
+ /**
36
+ * Converts a JSON string or object to its hexadecimal binary representation.
37
+ * @param {string} contractName The name of the contract.
38
+ * @param {string} type The type within the ABI to use for conversion.
39
+ * @param {string | object} json The JSON data as a string or object.
40
+ * @returns {string} The hexadecimal string representation of the binary data.
41
+ * @throws {Error} If parsing fails or an error occurs in the native module.
42
+ */
43
+ jsonToHex(contractName: string, type: string, json: string | object): string;
44
+ /**
45
+ * Converts a hexadecimal binary string to its JSON representation.
46
+ * @param {string} contractName The name of the contract.
47
+ * @param {string} type The type within the ABI to use for conversion.
48
+ * @param {string} hex The hexadecimal string to convert.
49
+ * @returns {any} The parsed JSON object.
50
+ * @throws {Error} If parsing fails or an error occurs in the native module.
51
+ */
52
+ hexToJson(contractName: string, type: string, hex: string): any;
53
+ /**
54
+ * Converts a binary buffer to its JSON representation.
55
+ * @param {string} contractName The name of the contract.
56
+ * @param {string} type The type within the ABI to use for conversion.
57
+ * @param {Buffer} buffer The binary data as a Buffer.
58
+ * @returns {any} The parsed JSON object.
59
+ * @throws {Error} If parsing fails or an error occurs in the native module.
60
+ */
61
+ binToJson(contractName: string, type: string, buffer: Buffer): any;
62
+ /**
63
+ * Loads an ABI for a given contract.
64
+ * @param {string} contractName The name of the contract for which to load the ABI.
65
+ * @param {string | object} abi The ABI as a JSON string or object.
66
+ * @returns {boolean} True if the ABI was loaded successfully, false otherwise.
67
+ * @throws {Error} If the ABI format is invalid or loading fails.
68
+ */
69
+ loadAbi(contractName: string, abi: string | object): boolean;
70
+ /**
71
+ * Loads an ABI for a given contract from its hexadecimal representation.
72
+ * @param {string} contractName The name of the contract for which to load the ABI.
73
+ * @param {string} abihex The ABI as a hexadecimal string.
74
+ * @returns {boolean} True if the ABI was loaded successfully, false otherwise.
75
+ * @throws {Error} If loading fails.
76
+ */
77
+ loadAbiHex(contractName: string, abihex: string): boolean;
78
+ /**
79
+ * Retrieves the type name for a specific action within a contract's ABI.
80
+ * @param {string} contractName The name of the contract.
81
+ * @param {string} actionName The name of the action.
82
+ * @returns {string} The type name associated with the action.
83
+ * @throws {Error} If the contract or action is not found or another error occurs.
84
+ */
85
+ getTypeForAction(contractName: string, actionName: string): string;
86
+ /**
87
+ * Retrieves the type name for a specific table within a contract's ABI.
88
+ * @param {string} contractName The name of the contract.
89
+ * @param {string} table_name The name of the table.
90
+ * @returns {string} The type name associated with the table.
91
+ * @throws {Error} If the contract or table is not found or another error occurs.
92
+ */
93
+ getTypeForTable(contractName: string, table_name: string): string;
94
+ /**
95
+ * Deletes a contract's ABI from the abieos context.
96
+ * @param {string} contractName The name of the contract to delete.
97
+ * @returns {boolean} True if the contract was successfully deleted, false otherwise.
98
+ * @throws {Error} If deletion fails.
99
+ */
100
+ deleteContract(contractName: string): boolean;
101
+ }
102
+
103
+ declare const abieos: any;
104
+
105
+ export { }
@@ -1,19 +1,105 @@
1
- export declare class Abieos {
2
- private static instance;
3
- static native: typeof abieos;
4
- private constructor();
5
- static getInstance(): Abieos;
6
- stringToName(nameString: string): BigInteger;
7
- jsonToHex(contractName: string, type: string, json: string | object): string;
8
- hexToJson(contractName: string, type: string, hex: string): any;
9
- binToJson(contractName: string, type: string, buffer: Buffer): any;
10
- loadAbi(contractName: string, abi: string | object): boolean;
11
- loadAbiHex(contractName: string, abihex: string): boolean;
12
- getTypeForAction(contractName: string, actionName: string): string;
13
- getTypeForTable(contractName: string, table_name: string): string;
14
- deleteContract(contractName: string): boolean;
15
- }
16
-
17
- declare const abieos: any;
18
-
19
- export { }
1
+ /**
2
+ * Abieos class provides a singleton instance for interacting with the native abieos module.
3
+ * This pattern is used to ensure a single global context for the underlying C++ abieos library,
4
+ * which manages internal state and resources.
5
+ */
6
+ export declare class Abieos {
7
+ static logTag: string;
8
+ private static instance;
9
+ static native: typeof abieos;
10
+ private static loadedContracts;
11
+ static debug: boolean;
12
+ /**
13
+ * Private constructor to enforce the Singleton pattern.
14
+ * Throws an error if an attempt is made to create a second instance.
15
+ */
16
+ private constructor();
17
+ /**
18
+ * Returns the singleton instance of the Abieos class.
19
+ * If an instance does not already exist, it creates one.
20
+ * @returns {Abieos} The singleton instance of Abieos.
21
+ */
22
+ static getInstance(): Abieos;
23
+ getLoadedAbis(): string[];
24
+ /**
25
+ * Cleans up all loaded contracts by deleting them from the native context.
26
+ * This is useful for freeing up resources and ensuring a clean state.
27
+ */
28
+ cleanup(): void;
29
+ /**
30
+ * Converts a string name to its corresponding 64-bit unsigned integer representation (BigInt).
31
+ * @param {string} nameString The string name to convert.
32
+ * @returns {BigInt} The BigInt representation of the name.
33
+ */
34
+ stringToName(nameString: string): BigInt;
35
+ /**
36
+ * Converts a JSON string or object to its hexadecimal binary representation.
37
+ * @param {string} contractName The name of the contract.
38
+ * @param {string} type The type within the ABI to use for conversion.
39
+ * @param {string | object} json The JSON data as a string or object.
40
+ * @returns {string} The hexadecimal string representation of the binary data.
41
+ * @throws {Error} If parsing fails or an error occurs in the native module.
42
+ */
43
+ jsonToHex(contractName: string, type: string, json: string | object): string;
44
+ /**
45
+ * Converts a hexadecimal binary string to its JSON representation.
46
+ * @param {string} contractName The name of the contract.
47
+ * @param {string} type The type within the ABI to use for conversion.
48
+ * @param {string} hex The hexadecimal string to convert.
49
+ * @returns {any} The parsed JSON object.
50
+ * @throws {Error} If parsing fails or an error occurs in the native module.
51
+ */
52
+ hexToJson(contractName: string, type: string, hex: string): any;
53
+ /**
54
+ * Converts a binary buffer to its JSON representation.
55
+ * @param {string} contractName The name of the contract.
56
+ * @param {string} type The type within the ABI to use for conversion.
57
+ * @param {Buffer} buffer The binary data as a Buffer.
58
+ * @returns {any} The parsed JSON object.
59
+ * @throws {Error} If parsing fails or an error occurs in the native module.
60
+ */
61
+ binToJson(contractName: string, type: string, buffer: Buffer): any;
62
+ /**
63
+ * Loads an ABI for a given contract.
64
+ * @param {string} contractName The name of the contract for which to load the ABI.
65
+ * @param {string | object} abi The ABI as a JSON string or object.
66
+ * @returns {boolean} True if the ABI was loaded successfully, false otherwise.
67
+ * @throws {Error} If the ABI format is invalid or loading fails.
68
+ */
69
+ loadAbi(contractName: string, abi: string | object): boolean;
70
+ /**
71
+ * Loads an ABI for a given contract from its hexadecimal representation.
72
+ * @param {string} contractName The name of the contract for which to load the ABI.
73
+ * @param {string} abihex The ABI as a hexadecimal string.
74
+ * @returns {boolean} True if the ABI was loaded successfully, false otherwise.
75
+ * @throws {Error} If loading fails.
76
+ */
77
+ loadAbiHex(contractName: string, abihex: string): boolean;
78
+ /**
79
+ * Retrieves the type name for a specific action within a contract's ABI.
80
+ * @param {string} contractName The name of the contract.
81
+ * @param {string} actionName The name of the action.
82
+ * @returns {string} The type name associated with the action.
83
+ * @throws {Error} If the contract or action is not found or another error occurs.
84
+ */
85
+ getTypeForAction(contractName: string, actionName: string): string;
86
+ /**
87
+ * Retrieves the type name for a specific table within a contract's ABI.
88
+ * @param {string} contractName The name of the contract.
89
+ * @param {string} table_name The name of the table.
90
+ * @returns {string} The type name associated with the table.
91
+ * @throws {Error} If the contract or table is not found or another error occurs.
92
+ */
93
+ getTypeForTable(contractName: string, table_name: string): string;
94
+ /**
95
+ * Deletes a contract's ABI from the abieos context.
96
+ * @param {string} contractName The name of the contract to delete.
97
+ * @returns {boolean} True if the contract was successfully deleted, false otherwise.
98
+ * @throws {Error} If deletion fails.
99
+ */
100
+ deleteContract(contractName: string): boolean;
101
+ }
102
+
103
+ declare const abieos: any;
104
+
105
+ export { }
package/dist/abieos.cjs CHANGED
@@ -1,122 +1,261 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // lib/abieos.ts
21
- var abieos_exports = {};
22
- __export(abieos_exports, {
23
- Abieos: () => Abieos
24
- });
25
- module.exports = __toCommonJS(abieos_exports);
26
-
27
- // node_modules/tsup/assets/cjs_shims.js
28
- var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
29
- var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
30
-
31
- // lib/abieos.ts
32
- var import_module = require("module");
33
- var abieos = (0, import_module.createRequire)(importMetaUrl)("./abieos.node");
34
- var Abieos = class _Abieos {
35
- static instance;
36
- static native;
37
- constructor() {
38
- if (_Abieos.instance) {
39
- throw new Error("This class is a Singleton!");
40
- }
41
- _Abieos.native = abieos;
42
- }
43
- static getInstance() {
44
- if (!_Abieos.instance) {
45
- _Abieos.instance = new _Abieos();
46
- }
47
- return _Abieos.instance;
48
- }
49
- stringToName(nameString) {
50
- return _Abieos.native.string_to_name(nameString);
51
- }
52
- jsonToHex(contractName, type, json) {
53
- const jsonData = typeof json === "object" ? JSON.stringify(json) : json;
54
- const data = _Abieos.native.json_to_hex(contractName, type, jsonData);
55
- if (data === "PARSING_ERROR") {
56
- throw new Error("failed to parse data");
57
- } else {
58
- return data;
59
- }
60
- }
61
- hexToJson(contractName, type, hex) {
62
- const data = _Abieos.native.hex_to_json(contractName, type, hex);
63
- if (data) {
64
- try {
65
- return JSON.parse(data);
66
- } catch (e) {
67
- throw new Error("failed to parse json string: " + data);
68
- }
69
- } else {
70
- throw new Error("failed to parse hex data");
71
- }
72
- }
73
- binToJson(contractName, type, buffer) {
74
- const data = _Abieos.native.bin_to_json(contractName, type, buffer);
75
- if (data[0] === "{" || data[0] === "[") {
76
- try {
77
- return JSON.parse(data);
78
- } catch (e) {
79
- throw new Error("json parse error");
80
- }
81
- } else {
82
- throw new Error(data);
83
- }
84
- }
85
- loadAbi(contractName, abi) {
86
- if (typeof abi === "string") {
87
- return _Abieos.native.load_abi(contractName, abi);
88
- } else {
89
- if (typeof abi === "object") {
90
- return _Abieos.native.load_abi(contractName, JSON.stringify(abi));
91
- } else {
92
- throw new Error("ABI must be a String or Object");
93
- }
94
- }
95
- }
96
- loadAbiHex(contractName, abihex) {
97
- return _Abieos.native.load_abi_hex(contractName, abihex);
98
- }
99
- getTypeForAction(contractName, actionName) {
100
- const result = _Abieos.native.get_type_for_action(contractName, actionName);
101
- if (result === "NOT_FOUND") {
102
- throw new Error(`[node-abieos] action ` + actionName + " not found on contract " + contractName);
103
- } else {
104
- return result;
105
- }
106
- }
107
- getTypeForTable(contractName, table_name) {
108
- const result = _Abieos.native.get_type_for_table(contractName, table_name);
109
- if (result === "NOT_FOUND") {
110
- throw new Error(`[node-abieos] table ` + table_name + " not found on contract " + contractName);
111
- } else {
112
- return result;
113
- }
114
- }
115
- deleteContract(contractName) {
116
- return _Abieos.native.delete_contract(contractName);
117
- }
118
- };
119
- // Annotate the CommonJS export names for ESM import in node:
120
- 0 && (module.exports = {
121
- Abieos
122
- });
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // lib/abieos.ts
21
+ var abieos_exports = {};
22
+ __export(abieos_exports, {
23
+ Abieos: () => Abieos
24
+ });
25
+ module.exports = __toCommonJS(abieos_exports);
26
+
27
+ // node_modules/tsup/assets/cjs_shims.js
28
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
29
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
30
+
31
+ // lib/abieos.ts
32
+ var import_module = require("module");
33
+ var abieos = (0, import_module.createRequire)(importMetaUrl)("./abieos.node");
34
+ var Abieos = class _Abieos {
35
+ static logTag = "[node-abieos]";
36
+ static instance;
37
+ static native;
38
+ static loadedContracts = /* @__PURE__ */ new Map();
39
+ static debug = false;
40
+ /**
41
+ * Private constructor to enforce the Singleton pattern.
42
+ * Throws an error if an attempt is made to create a second instance.
43
+ */
44
+ constructor() {
45
+ if (_Abieos.instance) {
46
+ throw new Error(`${_Abieos.logTag} Abieos is a Singleton class. Use Abieos.getInstance() to get the instance.`);
47
+ }
48
+ _Abieos.native = abieos;
49
+ }
50
+ /**
51
+ * Returns the singleton instance of the Abieos class.
52
+ * If an instance does not already exist, it creates one.
53
+ * @returns {Abieos} The singleton instance of Abieos.
54
+ */
55
+ static getInstance() {
56
+ if (!_Abieos.instance) {
57
+ _Abieos.instance = new _Abieos();
58
+ }
59
+ return _Abieos.instance;
60
+ }
61
+ getLoadedAbis() {
62
+ return Array.from(_Abieos.loadedContracts.keys());
63
+ }
64
+ /**
65
+ * Cleans up all loaded contracts by deleting them from the native context.
66
+ * This is useful for freeing up resources and ensuring a clean state.
67
+ */
68
+ cleanup() {
69
+ const errors = [];
70
+ _Abieos.loadedContracts.forEach((_, contractName) => {
71
+ try {
72
+ if (_Abieos.debug) {
73
+ console.log(`${_Abieos.logTag} Cleaning up contract '${contractName}'...`);
74
+ }
75
+ _Abieos.native.delete_contract(contractName);
76
+ _Abieos.loadedContracts.delete(contractName);
77
+ } catch (e) {
78
+ errors.push({ contractName, error: e.message });
79
+ console.error(`${_Abieos.logTag} Failed to delete contract '${contractName}' during cleanup: ${e.message}`);
80
+ }
81
+ });
82
+ if (errors.length > 0) {
83
+ throw new Error(`${_Abieos.logTag} Errors during cleanup: ${JSON.stringify(errors)}`);
84
+ }
85
+ }
86
+ /**
87
+ * Converts a string name to its corresponding 64-bit unsigned integer representation (BigInt).
88
+ * @param {string} nameString The string name to convert.
89
+ * @returns {BigInt} The BigInt representation of the name.
90
+ */
91
+ stringToName(nameString) {
92
+ try {
93
+ return _Abieos.native.string_to_name(nameString);
94
+ } catch (e) {
95
+ throw new Error(`${_Abieos.logTag} Failed to convert string to name '${nameString}': ${e.message}`);
96
+ }
97
+ }
98
+ /**
99
+ * Converts a JSON string or object to its hexadecimal binary representation.
100
+ * @param {string} contractName The name of the contract.
101
+ * @param {string} type The type within the ABI to use for conversion.
102
+ * @param {string | object} json The JSON data as a string or object.
103
+ * @returns {string} The hexadecimal string representation of the binary data.
104
+ * @throws {Error} If parsing fails or an error occurs in the native module.
105
+ */
106
+ jsonToHex(contractName, type, json) {
107
+ const jsonData = typeof json === "object" ? JSON.stringify(json) : json;
108
+ try {
109
+ return _Abieos.native.json_to_hex(contractName, type, jsonData);
110
+ } catch (e) {
111
+ throw new Error(`${_Abieos.logTag} Failed to convert JSON to hex for contract '${contractName}', type '${type}': ${e.message}`);
112
+ }
113
+ }
114
+ /**
115
+ * Converts a hexadecimal binary string to its JSON representation.
116
+ * @param {string} contractName The name of the contract.
117
+ * @param {string} type The type within the ABI to use for conversion.
118
+ * @param {string} hex The hexadecimal string to convert.
119
+ * @returns {any} The parsed JSON object.
120
+ * @throws {Error} If parsing fails or an error occurs in the native module.
121
+ */
122
+ hexToJson(contractName, type, hex) {
123
+ try {
124
+ const data = _Abieos.native.hex_to_json(contractName, type, hex);
125
+ try {
126
+ return JSON.parse(data);
127
+ } catch (parseError) {
128
+ throw new Error(`${_Abieos.logTag} Failed to parse JSON string from hex for contract '${contractName}', type '${type}'. Received: ${data}. Parse error: ${parseError.message}`);
129
+ }
130
+ } catch (e) {
131
+ throw new Error(`${_Abieos.logTag} Native error when converting hex to JSON for contract '${contractName}', type '${type}': ${e.message}`);
132
+ }
133
+ }
134
+ /**
135
+ * Converts a binary buffer to its JSON representation.
136
+ * @param {string} contractName The name of the contract.
137
+ * @param {string} type The type within the ABI to use for conversion.
138
+ * @param {Buffer} buffer The binary data as a Buffer.
139
+ * @returns {any} The parsed JSON object.
140
+ * @throws {Error} If parsing fails or an error occurs in the native module.
141
+ */
142
+ binToJson(contractName, type, buffer) {
143
+ try {
144
+ const data = _Abieos.native.bin_to_json(contractName, type, buffer);
145
+ try {
146
+ return JSON.parse(data);
147
+ } catch (parseError) {
148
+ throw new Error(`${_Abieos.logTag} Failed to parse JSON string from binary for contract '${contractName}', type '${type}'. Received: ${data}. Parse error: ${parseError.message}`);
149
+ }
150
+ } catch (e) {
151
+ throw new Error(`${_Abieos.logTag} Native error when converting binary to JSON for contract '${contractName}', type '${type}': ${e.message}`);
152
+ }
153
+ }
154
+ /**
155
+ * Loads an ABI for a given contract.
156
+ * @param {string} contractName The name of the contract for which to load the ABI.
157
+ * @param {string | object} abi The ABI as a JSON string or object.
158
+ * @returns {boolean} True if the ABI was loaded successfully, false otherwise.
159
+ * @throws {Error} If the ABI format is invalid or loading fails.
160
+ */
161
+ loadAbi(contractName, abi) {
162
+ if (_Abieos.debug && _Abieos.loadedContracts.has(contractName)) {
163
+ console.info(`${_Abieos.logTag} Contract '${contractName}' is already loaded. Updating ABI...`);
164
+ }
165
+ const abiString = typeof abi === "object" ? JSON.stringify(abi) : abi;
166
+ if (typeof abiString !== "string") {
167
+ throw new Error(`${_Abieos.logTag} ABI must be a String or Object.`);
168
+ }
169
+ try {
170
+ const loaded = _Abieos.native.load_abi(contractName, abiString);
171
+ if (loaded) {
172
+ _Abieos.loadedContracts.set(contractName, Date.now());
173
+ if (_Abieos.debug) {
174
+ console.log(`${_Abieos.logTag} Loaded ABI for contract '${contractName}'.`);
175
+ }
176
+ }
177
+ return loaded;
178
+ } catch (e) {
179
+ throw new Error(`${_Abieos.logTag} Failed to load ABI for contract '${contractName}': ${e.message}`);
180
+ }
181
+ }
182
+ /**
183
+ * Loads an ABI for a given contract from its hexadecimal representation.
184
+ * @param {string} contractName The name of the contract for which to load the ABI.
185
+ * @param {string} abihex The ABI as a hexadecimal string.
186
+ * @returns {boolean} True if the ABI was loaded successfully, false otherwise.
187
+ * @throws {Error} If loading fails.
188
+ */
189
+ loadAbiHex(contractName, abihex) {
190
+ if (typeof abihex !== "string") {
191
+ throw new Error(`${_Abieos.logTag} ABI hex must be a String.`);
192
+ }
193
+ if (_Abieos.debug && _Abieos.loadedContracts.has(contractName)) {
194
+ console.info(`${_Abieos.logTag} Contract '${contractName}' is already loaded. Updating ABI...`);
195
+ }
196
+ try {
197
+ const loaded = _Abieos.native.load_abi_hex(contractName, abihex);
198
+ if (loaded) {
199
+ _Abieos.loadedContracts.set(contractName, Date.now());
200
+ if (_Abieos.debug) {
201
+ console.log(`${_Abieos.logTag} Loaded ABI hex for contract '${contractName}'.`);
202
+ }
203
+ }
204
+ return loaded;
205
+ } catch (e) {
206
+ throw new Error(`${_Abieos.logTag} Failed to load ABI hex for contract '${contractName}': ${e.message}`);
207
+ }
208
+ }
209
+ /**
210
+ * Retrieves the type name for a specific action within a contract's ABI.
211
+ * @param {string} contractName The name of the contract.
212
+ * @param {string} actionName The name of the action.
213
+ * @returns {string} The type name associated with the action.
214
+ * @throws {Error} If the contract or action is not found or another error occurs.
215
+ */
216
+ getTypeForAction(contractName, actionName) {
217
+ try {
218
+ return _Abieos.native.get_type_for_action(contractName, actionName);
219
+ } catch (e) {
220
+ throw new Error(`${_Abieos.logTag} Failed to get type for action '${actionName}' in contract '${contractName}': ${e.message}`);
221
+ }
222
+ }
223
+ /**
224
+ * Retrieves the type name for a specific table within a contract's ABI.
225
+ * @param {string} contractName The name of the contract.
226
+ * @param {string} table_name The name of the table.
227
+ * @returns {string} The type name associated with the table.
228
+ * @throws {Error} If the contract or table is not found or another error occurs.
229
+ */
230
+ getTypeForTable(contractName, table_name) {
231
+ try {
232
+ return _Abieos.native.get_type_for_table(contractName, table_name);
233
+ } catch (e) {
234
+ throw new Error(`${_Abieos.logTag} Failed to get type for table '${table_name}' in contract '${contractName}': ${e.message}`);
235
+ }
236
+ }
237
+ /**
238
+ * Deletes a contract's ABI from the abieos context.
239
+ * @param {string} contractName The name of the contract to delete.
240
+ * @returns {boolean} True if the contract was successfully deleted, false otherwise.
241
+ * @throws {Error} If deletion fails.
242
+ */
243
+ deleteContract(contractName) {
244
+ try {
245
+ const deleted = _Abieos.native.delete_contract(contractName);
246
+ if (deleted) {
247
+ _Abieos.loadedContracts.delete(contractName);
248
+ if (_Abieos.debug) {
249
+ console.log(`${_Abieos.logTag} Deleted contract '${contractName}' from abieos context.`);
250
+ }
251
+ }
252
+ return deleted;
253
+ } catch (e) {
254
+ throw new Error(`${_Abieos.logTag} Failed to delete contract '${contractName}': ${e.message}`);
255
+ }
256
+ }
257
+ };
258
+ // Annotate the CommonJS export names for ESM import in node:
259
+ 0 && (module.exports = {
260
+ Abieos
261
+ });