forked from EOSIO/abieos
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
project sync, update bundle generation with tsup
- Loading branch information
Showing
23 changed files
with
2,007 additions
and
1,398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ build | |
node_modules | ||
*.log | ||
.idea | ||
.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Abieos } from './_tsup-dts-rollup.cjs'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Abieos } from './_tsup-dts-rollup.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.