Skip to content

Commit

Permalink
project sync, update bundle generation with tsup
Browse files Browse the repository at this point in the history
  • Loading branch information
igorls committed Oct 27, 2024
1 parent fad1450 commit 4c3ddbd
Show file tree
Hide file tree
Showing 23 changed files with 2,007 additions and 1,398 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build
node_modules
*.log
.idea
.cache
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.24)
cmake_minimum_required (VERSION 3.22)
project(node_abieos VERSION 3.2.1 LANGUAGES CXX C)

add_definitions(-DNAPI_VERSION=9)
Expand Down
Binary file removed bun.lockb
Binary file not shown.
9 changes: 5 additions & 4 deletions lib/abieos.d.ts → dist/_tsup-dts-rollup.d.cts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/// <reference types="node" />
declare const abieos: any;

export declare class Abieos {
private static instance;
static native: typeof abieos;
private static instanceId;
private constructor();
static getInstance(): Abieos;
stringToName(nameString: string): BigInteger;
Expand All @@ -16,5 +15,7 @@ export declare class Abieos {
getTypeForTable(contractName: string, table_name: string): string;
deleteContract(contractName: string): boolean;
}
export {};
//# sourceMappingURL=abieos.d.ts.map

declare const abieos: any;

export { }
21 changes: 21 additions & 0 deletions dist/_tsup-dts-rollup.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference types="node" />

export declare class Abieos {
private static instance;
static native: typeof abieos;
private constructor();
static getInstance(): Abieos;
stringToName(nameString: string): BigInteger;
jsonToHex(contractName: string, type: string, json: string | object): string;
hexToJson(contractName: string, type: string, hex: string): any;
binToJson(contractName: string, type: string, buffer: Buffer): any;
loadAbi(contractName: string, abi: string | object): boolean;
loadAbiHex(contractName: string, abihex: string): boolean;
getTypeForAction(contractName: string, actionName: string): string;
getTypeForTable(contractName: string, table_name: string): string;
deleteContract(contractName: string): boolean;
}

declare const abieos: any;

export { }
122 changes: 122 additions & 0 deletions dist/abieos.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// lib/abieos.ts
var abieos_exports = {};
__export(abieos_exports, {
Abieos: () => Abieos
});
module.exports = __toCommonJS(abieos_exports);

// node_modules/tsup/assets/cjs_shims.js
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();

// lib/abieos.ts
var import_module = require("module");
var abieos = (0, import_module.createRequire)(importMetaUrl)("./abieos.node");
var Abieos = class _Abieos {
static instance;
static native;
constructor() {
if (_Abieos.instance) {
throw new Error("This class is a Singleton!");
}
_Abieos.native = abieos;
}
static getInstance() {
if (!_Abieos.instance) {
_Abieos.instance = new _Abieos();
}
return _Abieos.instance;
}
stringToName(nameString) {
return _Abieos.native.string_to_name(nameString);
}
jsonToHex(contractName, type, json) {
const jsonData = typeof json === "object" ? JSON.stringify(json) : json;
const data = _Abieos.native.json_to_hex(contractName, type, jsonData);
if (data === "PARSING_ERROR") {
throw new Error("failed to parse data");
} else {
return data;
}
}
hexToJson(contractName, type, hex) {
const data = _Abieos.native.hex_to_json(contractName, type, hex);
if (data) {
try {
return JSON.parse(data);
} catch (e) {
throw new Error("failed to parse json string: " + data);
}
} else {
throw new Error("failed to parse hex data");
}
}
binToJson(contractName, type, buffer) {
const data = _Abieos.native.bin_to_json(contractName, type, buffer);
if (data[0] === "{" || data[0] === "[") {
try {
return JSON.parse(data);
} catch (e) {
throw new Error("json parse error");
}
} else {
throw new Error(data);
}
}
loadAbi(contractName, abi) {
if (typeof abi === "string") {
return _Abieos.native.load_abi(contractName, abi);
} else {
if (typeof abi === "object") {
return _Abieos.native.load_abi(contractName, JSON.stringify(abi));
} else {
throw new Error("ABI must be a String or Object");
}
}
}
loadAbiHex(contractName, abihex) {
return _Abieos.native.load_abi_hex(contractName, abihex);
}
getTypeForAction(contractName, actionName) {
const result = _Abieos.native.get_type_for_action(contractName, actionName);
if (result === "NOT_FOUND") {
throw new Error(`[node-abieos] action ` + actionName + " not found on contract " + contractName);
} else {
return result;
}
}
getTypeForTable(contractName, table_name) {
const result = _Abieos.native.get_type_for_table(contractName, table_name);
if (result === "NOT_FOUND") {
throw new Error(`[node-abieos] table ` + table_name + " not found on contract " + contractName);
} else {
return result;
}
}
deleteContract(contractName) {
return _Abieos.native.delete_contract(contractName);
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Abieos
});
1 change: 1 addition & 0 deletions dist/abieos.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Abieos } from './_tsup-dts-rollup.cjs';
1 change: 1 addition & 0 deletions dist/abieos.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Abieos } from './_tsup-dts-rollup.js';
91 changes: 91 additions & 0 deletions dist/abieos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// lib/abieos.ts
import { createRequire } from "module";
var abieos = createRequire(import.meta.url)("./abieos.node");
var Abieos = class _Abieos {
static instance;
static native;
constructor() {
if (_Abieos.instance) {
throw new Error("This class is a Singleton!");
}
_Abieos.native = abieos;
}
static getInstance() {
if (!_Abieos.instance) {
_Abieos.instance = new _Abieos();
}
return _Abieos.instance;
}
stringToName(nameString) {
return _Abieos.native.string_to_name(nameString);
}
jsonToHex(contractName, type, json) {
const jsonData = typeof json === "object" ? JSON.stringify(json) : json;
const data = _Abieos.native.json_to_hex(contractName, type, jsonData);
if (data === "PARSING_ERROR") {
throw new Error("failed to parse data");
} else {
return data;
}
}
hexToJson(contractName, type, hex) {
const data = _Abieos.native.hex_to_json(contractName, type, hex);
if (data) {
try {
return JSON.parse(data);
} catch (e) {
throw new Error("failed to parse json string: " + data);
}
} else {
throw new Error("failed to parse hex data");
}
}
binToJson(contractName, type, buffer) {
const data = _Abieos.native.bin_to_json(contractName, type, buffer);
if (data[0] === "{" || data[0] === "[") {
try {
return JSON.parse(data);
} catch (e) {
throw new Error("json parse error");
}
} else {
throw new Error(data);
}
}
loadAbi(contractName, abi) {
if (typeof abi === "string") {
return _Abieos.native.load_abi(contractName, abi);
} else {
if (typeof abi === "object") {
return _Abieos.native.load_abi(contractName, JSON.stringify(abi));
} else {
throw new Error("ABI must be a String or Object");
}
}
}
loadAbiHex(contractName, abihex) {
return _Abieos.native.load_abi_hex(contractName, abihex);
}
getTypeForAction(contractName, actionName) {
const result = _Abieos.native.get_type_for_action(contractName, actionName);
if (result === "NOT_FOUND") {
throw new Error(`[node-abieos] action ` + actionName + " not found on contract " + contractName);
} else {
return result;
}
}
getTypeForTable(contractName, table_name) {
const result = _Abieos.native.get_type_for_table(contractName, table_name);
if (result === "NOT_FOUND") {
throw new Error(`[node-abieos] table ` + table_name + " not found on contract " + contractName);
} else {
return result;
}
}
deleteContract(contractName) {
return _Abieos.native.delete_contract(contractName);
}
};
export {
Abieos
};
Binary file added dist/abieos.node
Binary file not shown.
100 changes: 100 additions & 0 deletions dist/abieos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { createRequire } from "module";
const abieos = createRequire(import.meta.url)('./abieos.node');

export class Abieos {

private static instance: Abieos;
public static native: typeof abieos;

private constructor() {
if (Abieos.instance) {
throw new Error("This class is a Singleton!");
}
Abieos.native = abieos;
}

public static getInstance(): Abieos {
if (!Abieos.instance) {
Abieos.instance = new Abieos();
}
return Abieos.instance;
}

public stringToName(nameString: string): BigInteger {
return Abieos.native.string_to_name(nameString) as BigInteger;
}

public jsonToHex(contractName: string, type: string, json: string | object): string {
const jsonData = typeof json === 'object' ? JSON.stringify(json) : json
const data: string = Abieos.native.json_to_hex(contractName, type, jsonData);
if (data === 'PARSING_ERROR') {
throw new Error('failed to parse data');
} else {
return data;
}
}

public hexToJson(contractName: string, type: string, hex: string): any {
const data = Abieos.native.hex_to_json(contractName, type, hex);
if (data) {
try {
return JSON.parse(data);
} catch (e) {
throw new Error('failed to parse json string: ' + data);
}
} else {
throw new Error('failed to parse hex data');
}
}

public binToJson(contractName: string, type: string, buffer: Buffer): any {
const data = Abieos.native.bin_to_json(contractName, type, buffer);
if (data[0] === '{' || data[0] === '[') {
try {
return JSON.parse(data);
} catch (e) {
throw new Error('json parse error');
}
} else {
throw new Error(data);
}
}

public loadAbi(contractName: string, abi: string | object): boolean {
if (typeof abi === 'string') {
return Abieos.native.load_abi(contractName, abi) as boolean;
} else {
if (typeof abi === 'object') {
return Abieos.native.load_abi(contractName, JSON.stringify(abi)) as boolean;
} else {
throw new Error('ABI must be a String or Object');
}
}
}

public loadAbiHex(contractName: string, abihex: string): boolean {
return Abieos.native.load_abi_hex(contractName, abihex) as boolean;
}

public getTypeForAction(contractName: string, actionName: string): string {
const result = Abieos.native.get_type_for_action(contractName, actionName);
if (result === 'NOT_FOUND') {
throw new Error(`[node-abieos] action ` + actionName + ' not found on contract ' + contractName);
} else {
return result;
}
}

public getTypeForTable(contractName: string, table_name: string): string {
const result = Abieos.native.get_type_for_table(contractName, table_name);
if (result === 'NOT_FOUND') {
throw new Error(`[node-abieos] table ` + table_name + ' not found on contract ' + contractName);
} else {
return result;
}
}

public deleteContract(contractName: string): boolean {
return Abieos.native.delete_contract(contractName) as boolean;
}
}
Loading

0 comments on commit 4c3ddbd

Please sign in to comment.