Skip to content

Commit

Permalink
Merge pull request #6 from decentldotland/switch-net
Browse files Browse the repository at this point in the history
feat: v1.0.6 stable release
  • Loading branch information
charmful0x authored Jan 29, 2024
2 parents 02073be + 94c17ed commit aa6dddb
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 51 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ npm install && npm run build

#### Build size

- `dist/index.cjs.js` <span style="color:green;">3.20 kB │ gzip: 1.04 kB</span></br>
- `dist/index.umd.js` <span style="color:green;">3.40 kB │ gzip: 1.14 kB</span></br>
- `dist/index.es.js` <span style="color:green;">4.39 kB │ gzip: 1.14 kB</span>
- `dist/index.cjs.js` <span style="color:green;">3.46 kB │ gzip: 1.07 kB</span></br>
- `dist/index.umd.js` <span style="color:green;">3.66 kB │ gzip: 1.17 kB</span></br>
- `dist/index.es.js` <span style="color:green;">4.74 kB │ gzip: 1.18 kB</span>

## Install

Expand Down
2 changes: 1 addition & 1 deletion dist/index.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ declare class Actions extends Base {
read<T>(id: string): Promise<T>;
write<T>(id: string, inputs: Inputs): Promise<T>;
deploy<T>(src: string, initState: string): Promise<T>;
fork<T>(id: string, net: string, state?: string): Promise<T>;
kvGet<T>(id: string): Promise<T>;
}
declare class Mem extends Actions {
}
Expand Down
183 changes: 138 additions & 45 deletions dist/index.es.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,153 @@
const i = "https://mem-cli-server-482a8c7c1299.herokuapp.com/mem-cli";
function p(o, t) {
const n = o.split("").map((s) => s.charCodeAt(0)), e = {
const c = "https://mem-cli-server-482a8c7c1299.herokuapp.com/mem-cli";
function h(r, t) {
const n = r.split("").map((a) => a.charCodeAt(0)), s = {
contractOwner: "",
contentType: "application/javascript",
contractSrc: n,
initState: t
}, a = [
}, e = [
{ name: "Content-Type", value: "application/javascript" },
{ name: "Owner", value: "" },
{ name: "App-Name", value: "EM" },
{ name: "Type", value: "Serverless-Function" },
{ name: "EM-Bundled", value: "true" },
{ name: "Size", value: String(n.length) }
];
return { dataTx: e, tags: a };
return { dataTx: s, tags: e };
}
class u {
async readFunction(t) {
const n = `https://api.mem.tech/api/state/${t}`, a = await fetch(n, { headers: {
async function p(r) {
var t;
try {
const n = r.split(".mem")[0], e = await fetch("https://api.mem.tech/api/state/GJn1h75nIAyMW5XWgzraL-Ldxr2Zb38WlLEVwk6CBDs", { headers: {
"Content-Type": "application/json"
} });
if (a.ok)
return await a.json();
throw new Error(a.statusText);
if (e.ok) {
const a = (t = await e.json()) == null ? void 0 : t.names;
if (n in a)
return a[n];
}
throw new Error(e.statusText);
} catch {
return null;
}
async writeFunction(t, n) {
const e = "https://api.mem.tech/api/transactions", c = {
method: "POST",
headers: {
}
class u {
constructor(t) {
this.network = t.network;
}
async readFunction(t) {
if (t.endsWith(".mem") && (t = await p(t)), this.network === "mainnet") {
const n = `https://api.mem.tech/api/state/${t}`, e = await fetch(n, { headers: {
"Content-Type": "application/json"
} });
if (e.ok)
return await e.json();
throw new Error(e.statusText);
}
if (this.network === "testnet") {
const n = `https://mem-testnet.xyz/state/${t}`, e = await fetch(n, { headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
functionId: t,
inputs: [
{
input: n
}
]
})
}, r = await fetch(e, c);
if (r.ok)
return await r.json();
throw new Error(r.statusText);
} });
if (e.ok)
return await e.json();
throw new Error(e.statusText);
}
}
async writeFunction(t, n) {
if (t.endsWith(".mem") && (t = await p(t)), this.network === "mainnet") {
const s = "https://api.mem.tech/api/transactions", o = {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
functionId: t,
inputs: [
{
input: n
}
]
})
}, i = await fetch(s, o);
if (i.ok)
return await i.json();
throw new Error(i.statusText);
}
if (this.network === "testnet") {
const s = "https://mem-testnet.xyz/write", a = {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
function_id: t,
input: JSON.stringify(n)
})
}, o = await fetch(s, a);
if (o.ok)
return await o.json();
throw new Error(o.statusText);
}
}
async deployFunction(t, n) {
const e = JSON.stringify(p(t, n)), s = await fetch(i, {
method: "post",
url: i,
body: e,
headers: {
Accept: "application/json",
if (this.network === "mainnet") {
const s = JSON.stringify(h(t, n)), a = await fetch(c, {
method: "post",
url: c,
body: s,
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
maxContentLength: 1e8,
maxBodyLength: 1e9
});
if (a.ok)
return { id: (await a.json()).txid };
throw new Error(a.statusText);
}
if (this.network === "testnet") {
const s = {
method: "post",
url: "https://mem-testnet.xyz/deploy",
body: JSON.stringify({
src: t,
state: n
}),
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
maxContentLength: 1e8,
maxBodyLength: 1e9
}, e = await fetch("https://mem-testnet.xyz/deploy", s);
if (e.ok)
return { id: (await e.json()).function_id };
throw new Error(e.statusText);
}
}
async forkFunction(t, n, s) {
if (this.network === "mainnet") {
const e = s ? `https://molext1.com/mem/fork/${t}/${n}/${s}` : `https://molext1.com/mem/fork/${t}/${n}`, o = await fetch(e, { headers: {
"Content-Type": "application/json"
},
maxContentLength: 1e8,
maxBodyLength: 1e9
});
if (s.ok)
return { id: (await s.json()).txid };
throw new Error(s.statusText);
} });
if (o.ok)
return await o.json();
throw new Error(o.statusText);
}
}
async kvFunction(t) {
if (this.network === "mainnet") {
const n = `https://mem-api.com/kv/${t}`, e = await fetch(n, { headers: {
"Content-Type": "application/json"
} });
if (e.ok)
return await e.json();
throw new Error(e.statusText);
}
}
}
class d extends u {
class m extends u {
async read(t) {
return await this.readFunction(t);
}
Expand All @@ -70,10 +157,16 @@ class d extends u {
async deploy(t, n) {
return await this.deployFunction(t, n);
}
async fork(t, n, s) {
return await this.forkFunction(t, n, s);
}
async kvGet(t) {
return await this.kvFunction(t);
}
}
class h extends d {
class d extends m {
}
export {
d as Actions,
h as Mem
m as Actions,
d as Mem
};
2 changes: 1 addition & 1 deletion dist/index.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions dist/utils/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ interface deployValues {
id: string;
}
export declare abstract class Base {
network: string;
constructor(options: {
network: string;
});
readFunction(id: string): Promise<any>;
writeFunction(id: string, inputs: Inputs): Promise<MEMResponseObject | any>;
deployFunction(src: string, initState: string): Promise<deployValues | string | any>;
forkFunction(id: string, net: string, state?: string): Promise<any>;
kvFunction(id: string): Promise<any>;
}
export {};
1 change: 1 addition & 0 deletions dist/utils/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export declare const TXS_BROADCASTER_URL = "https://mem-cli-server-482a8c7c1299.herokuapp.com/mem-cli";
export declare function applyMixins(derivedCtor: any, baseCtors: any[]): void;
export declare function generateFunctionFormat(sc: string, state: string): any;
export declare function resolveMemName(funcName: string): Promise<any>;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mem-sdk",
"version": "0.0.6",
"version": "1.0.6",
"description": "JS SDK for MEM Serverless Functions",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
Expand Down

0 comments on commit aa6dddb

Please sign in to comment.