Comparing version
import { u128 } from "as-bignum/assembly"; | ||
import { Candle } from "./Candle"; | ||
import { | ||
@@ -6,27 +7,2 @@ JSON | ||
@json | ||
class Candle { | ||
timestamp!: i64; | ||
high!: f64; | ||
low!: f64; | ||
open!: f64; | ||
close!: f64; | ||
constructor(timestamp: i64, high: f64, low: f64, open: f64, close: f64) { | ||
this.timestamp = timestamp; | ||
this.high = high; | ||
this.low = low; | ||
this.open = open; | ||
this.close = close; | ||
} | ||
} | ||
//console.log(JSON.stringify(candle)); | ||
const parsedCandleArray: Candle[] = JSON.parse<Candle[]>(`[{"timestamp":1620248400000,"high":573.3476371851107,"low":572.7653897862947,"close":572.7653897862947,"open":573.3476371851107},{"timestamp":1620249300000,"high":572.4966600947654,"low":572.3690847959957,"close":572.3690847959957,"open":572.4966600947654},{"timestamp":1620250200000,"high":572.2886600465616,"low":571.757999416375,"close":571.757999416375,"open":572.2886600465616},{"timestamp":1620251100000,"high":571.745549588537,"low":571.4831524457645,"close":571.4831524457645,"open":571.745549588537},{"timestamp":1620252000000,"high":571.4291070205617,"low":571.423771655803,"close":571.423771655803,"open":571.4291070205617},{"timestamp":1620252900000,"high":571.2682040427187,"low":570.0124454515138,"close":571.2543224050862,"open":571.2682040427187},{"timestamp":1620253800000,"high":571.950687856295,"low":571.950687856295,"close":571.950687856295,"open":571.950687856295},{"timestamp":1620254700000,"high":574.32247048919,"low":572.229619806987,"close":574.32247048919,"open":572.229619806987},{"timestamp":1620255600000,"high":573.7949788294341,"low":573.7949788294341,"close":573.7949788294341,"open":573.7949788294341},{"timestamp":1620256500000,"high":573.6703031128156,"low":573.6703031128156,"close":573.6703031128156,"open":573.6703031128156},{"timestamp":1620261000000,"high":573.4922654231464,"low":573.4922654231464,"close":573.4922654231464,"open":573.4922654231464},{"timestamp":1620261900000,"high":573.2630790607755,"low":572.1510958054668,"close":572.1510958054668,"open":573.2630790607755},{"timestamp":1620262800000,"high":570.381489136757,"low":570.381489136757,"close":570.381489136757,"open":570.381489136757},{"timestamp":1620264600000,"high":570.2742985701099,"low":570.0803689046074,"close":570.0803689046074,"open":570.2742985701099},{"timestamp":1620265500000,"high":570.1422401263446,"low":570.1422401263446,"close":570.1422401263446,"open":570.1422401263446},{"timestamp":1620266400000,"high":572.8052512272116,"low":572.8052201233321,"close":572.8052512272116,"open":572.8052201233321},{"timestamp":1620267300000,"high":572.7730922927839,"low":572.7447581107978,"close":572.7447581107978,"open":572.7730922927839},{"timestamp":1620268200000,"high":572.7272428903487,"low":572.7258230151764,"close":572.7258230151764,"open":572.7272428903487},{"timestamp":1620270900000,"high":572.2594215468664,"low":571.8195591664584,"close":571.8195591664584,"open":572.2578671930029},{"timestamp":1620271800000,"high":571.2809499888094,"low":571.2808568072832,"close":571.2808568072832,"open":571.2809499888094},{"timestamp":1620272700000,"high":571.1742152842157,"low":571.1742152842157,"close":571.1742152842157,"open":571.1742152842157},{"timestamp":1620273600000,"high":571.1716102454611,"low":571.0288842515337,"close":571.0288842515337,"open":571.0642228722581},{"timestamp":1620275400000,"high":571.0203010949516,"low":571.0203010949516,"close":571.0203010949516,"open":571.0203010949516},{"timestamp":1620277200000,"high":570.261632018576,"low":570.261632018576,"close":570.261632018576,"open":570.261632018576},{"timestamp":1620279000000,"high":570.1348876529629,"low":570.1348876529629,"close":570.1348876529629,"open":570.1348876529629},{"timestamp":1620279900000,"high":570.199730991694,"low":570.199730991694,"close":570.199730991694,"open":570.199730991694},{"timestamp":1620282600000,"high":568.4408310147167,"low":568.4408310147167,"close":568.4408310147167,"open":568.4408310147167},{"timestamp":1620284400000,"high":567.8217236373331,"low":567.5896453383704,"close":567.5896453383704,"open":567.8217236373331},{"timestamp":1620288000000,"high":568.652510360092,"low":568.652510360092,"close":568.652510360092,"open":568.652510360092},{"timestamp":1620288900000,"high":569.0169039594798,"low":569.0169039594798,"close":569.0169039594798,"open":569.0169039594798},{"timestamp":1620289800000,"high":569.1372681718557,"low":569.1372681718557,"close":569.1372681718557,"open":569.1372681718557},{"timestamp":1620293400000,"high":569.1425890413165,"low":569.1425890413165,"close":569.1425890413165,"open":569.1425890413165},{"timestamp":1620294300000,"high":571.4603226652566,"low":569.668539984208,"close":571.3510882379371,"open":569.668539984208},{"timestamp":1620295200000,"high":575.0297756308146,"low":565.6188600247405,"close":575.0297756308146,"open":571.2768914562338},{"timestamp":1620296100000,"high":579.5414875855951,"low":578.0875180733055,"close":579.5414875855951,"open":578.0875180733055},{"timestamp":1620297000000,"high":580.4591998073045,"low":580.4591998073045,"close":580.4591998073045,"open":580.4591998073045},{"timestamp":1620299700000,"high":580.462401844569,"low":580.462401844569,"close":580.462401844569,"open":580.462401844569},{"timestamp":1620303300000,"high":580.450191330308,"low":580.450191330308,"close":580.450191330308,"open":580.450191330308},{"timestamp":1620305100000,"high":580.4060918534583,"low":580.4060918534583,"close":580.4060918534583,"open":580.4060918534583},{"timestamp":1620306000000,"high":580.2988479516713,"low":580.2988479516713,"close":580.2988479516713,"open":580.2988479516713},{"timestamp":1620306900000,"high":578.5227831917862,"low":578.5121109550881,"close":578.5121109550881,"open":578.5227831917862},{"timestamp":1620307800000,"high":578.3521310367136,"low":578.224208690017,"close":578.224208690017,"open":578.3521310367136},{"timestamp":1620308700000,"high":578.1781390176766,"low":578.1781390176766,"close":578.1781390176766,"open":578.1781390176766},{"timestamp":1620309600000,"high":574.5402154361069,"low":574.2966785397088,"close":574.5402154361069,"open":574.2966785397088},{"timestamp":1620310500000,"high":574.6374782052543,"low":574.3595582585991,"close":574.6374782052543,"open":574.3595582585991},{"timestamp":1620311400000,"high":575.0993626799352,"low":575.0993626799352,"close":575.0993626799352,"open":575.0993626799352},{"timestamp":1620313200000,"high":573.7701312728145,"low":573.7701312728145,"close":573.7701312728145,"open":573.7701312728145},{"timestamp":1620314100000,"high":573.3906631152785,"low":573.3906631152785,"close":573.3906631152785,"open":573.3906631152785},{"timestamp":1620315000000,"high":573.4334610811361,"low":573.4334610811361,"close":573.4334610811361,"open":573.4334610811361},{"timestamp":1620315900000,"high":571.6595888644223,"low":571.6595888644223,"close":571.6595888644223,"open":571.6595888644223},{"timestamp":1620316800000,"high":571.7534533028926,"low":571.7534533028926,"close":571.7534533028926,"open":571.7534533028926},{"timestamp":1620317700000,"high":577.9623648979384,"low":574.8537177533384,"close":576.1674529591473,"open":574.8537177533384},{"timestamp":1620318600000,"high":576.1563193117207,"low":576.0620257439493,"close":576.0620257439493,"open":576.1563193117207},{"timestamp":1620319500000,"high":574.275952158709,"low":571.177013121888,"close":571.177013121888,"open":574.275952158709},{"timestamp":1620321300000,"high":571.2079586608608,"low":571.2079586608608,"close":571.2079586608608,"open":571.2079586608608},{"timestamp":1620323100000,"high":571.324057673865,"low":571.324057673865,"close":571.324057673865,"open":571.324057673865},{"timestamp":1620324000000,"high":571.1253547573914,"low":570.0875973567182,"close":570.0875973567182,"open":571.1253547573914},{"timestamp":1620324900000,"high":570.0805475832676,"low":570.0805475832676,"close":570.0805475832676,"open":570.0805475832676},{"timestamp":1620325800000,"high":570.0257972684403,"low":559.1035539331212,"close":559.1035539331212,"open":570.0257972684403},{"timestamp":1620328500000,"high":557.5649037694549,"low":556.0279702412793,"close":556.0279702412793,"open":557.5649037694549},{"timestamp":1620329400000,"high":556.6968218685071,"low":556.6968218685071,"close":556.6968218685071,"open":556.6968218685071},{"timestamp":1620330300000,"high":560.7228138291837,"low":558.2216468935494,"close":560.7228138291837,"open":558.2216468935494},{"timestamp":1620332100000,"high":560.5876666979001,"low":560.5876666979001,"close":560.5876666979001,"open":560.5876666979001},{"timestamp":1620333000000,"high":560.5186489036859,"low":559.9302964393763,"close":559.9302964393763,"open":560.5186489036859},{"timestamp":1620335700000,"high":560.8859962694225,"low":560.8859962694225,"close":560.8859962694225,"open":560.8859962694225},{"timestamp":1620337500000,"high":562.6549059693484,"low":561.1228262312293,"close":562.6549059693484,"open":561.1228262312293},{"timestamp":1620338400000,"high":562.5749239504988,"low":562.5749239504988,"close":562.5749239504988,"open":562.5749239504988},{"timestamp":1620340200000,"high":564.1086094674863,"low":564.1086094674863,"close":564.1086094674863,"open":564.1086094674863},{"timestamp":1620341100000,"high":564.1156752788603,"low":564.1156752788603,"close":564.1156752788603,"open":564.1156752788603},{"timestamp":1620342000000,"high":563.8686326269438,"low":563.8686326269438,"close":563.8686326269438,"open":563.8686326269438},{"timestamp":1620343800000,"high":565.4032072056408,"low":565.4032072056408,"close":565.4032072056408,"open":565.4032072056408},{"timestamp":1620344700000,"high":564.9161906724804,"low":564.846451581273,"close":564.846451581273,"open":564.9161906724804},{"timestamp":1620345600000,"high":565.3129449522828,"low":563.3005556458523,"close":565.3129449522828,"open":563.3005556458523},{"timestamp":1620346500000,"high":566.8491299730733,"low":566.7792504378252,"close":566.7792504378252,"open":566.8491299730733},{"timestamp":1620347400000,"high":567.6311377719769,"low":566.8226586070456,"close":567.6311377719769,"open":566.8226586070456},{"timestamp":1620349200000,"high":568.393145669603,"low":562.3084190409248,"close":562.3084190409248,"open":568.393145669603},{"timestamp":1620350100000,"high":563.0673266288399,"low":563.0673266288399,"close":563.0673266288399,"open":563.0673266288399},{"timestamp":1620351000000,"high":563.0460469915702,"low":563.0460469915702,"close":563.0460469915702,"open":563.0460469915702},{"timestamp":1620351900000,"high":562.6940165863563,"low":562.6940165863563,"close":562.6940165863563,"open":562.6940165863563},{"timestamp":1620352800000,"high":562.2290121119479,"low":562.2290121119479,"close":562.2290121119479,"open":562.2290121119479},{"timestamp":1620354600000,"high":560.6865799646575,"low":559.1464640169283,"close":559.1464640169283,"open":560.6865799646575},{"timestamp":1620356400000,"high":558.6737643409452,"low":558.5032601234623,"close":558.5032601234623,"open":558.6737643409452},{"timestamp":1620358200000,"high":557.7252518300813,"low":557.7252518300813,"close":557.7252518300813,"open":557.7252518300813},{"timestamp":1620359100000,"high":559.452591197762,"low":559.452591197762,"close":559.452591197762,"open":559.452591197762},{"timestamp":1620360000000,"high":557.9238732313372,"low":551.1413593852167,"close":554.1625302396624,"open":557.9238732313372},{"timestamp":1620360900000,"high":555.7240520136215,"low":555.674531175535,"close":555.7240520136215,"open":555.674531175535},{"timestamp":1620361800000,"high":554.0781517227211,"low":554.0781517227211,"close":554.0781517227211,"open":554.0781517227211},{"timestamp":1620362700000,"high":555.9093975255644,"low":554.0935763098537,"close":555.9093975255644,"open":554.0935763098537},{"timestamp":1620363600000,"high":556.7596063111193,"low":556.0023730597429,"close":556.7596063111193,"open":556.0023730597429},{"timestamp":1620365400000,"high":558.3270073972132,"low":556.8114287909416,"close":558.3270073972132,"open":556.8114287909416},{"timestamp":1620367200000,"high":558.7824867555943,"low":558.7824867555943,"close":558.7824867555943,"open":558.7824867555943},{"timestamp":1620369000000,"high":562.0179021454524,"low":560.3025781550792,"close":562.0179021454524,"open":560.3025781550792},{"timestamp":1620369900000,"high":562.0080817771758,"low":562.0080817771758,"close":562.0080817771758,"open":562.0080817771758},{"timestamp":1620373500000,"high":560.4783187009747,"low":560.4783187009747,"close":560.4783187009747,"open":560.4783187009747},{"timestamp":1620374400000,"high":558.9505059072079,"low":558.9505059072079,"close":558.9505059072079,"open":558.9505059072079},{"timestamp":1620375300000,"high":558.7316785819487,"low":558.7315744378288,"close":558.7315744378288,"open":558.7316785819487},{"timestamp":1620376200000,"high":559.2700965276954,"low":558.7201382932576,"close":558.7201382932576,"open":559.2700965276954},{"timestamp":1620377100000,"high":559.7884860040957,"low":558.2725955125745,"close":559.7884860040957,"open":558.3870242987017},{"timestamp":1620378000000,"high":561.2454700974902,"low":559.7277145674427,"close":561.0931142383333,"open":559.7780560002528},{"timestamp":1620379800000,"high":562.5589149792357,"low":561.0392143359311,"close":562.5589149792357,"open":561.0392143359311},{"timestamp":1620381600000,"high":564.825992475405,"low":564.0806119374416,"close":564.825992475405,"open":564.0806119374416},{"timestamp":1620382500000,"high":564.8106789982139,"low":564.8003967441988,"close":564.8003967441988,"open":564.8106789982139},{"timestamp":1620383400000,"high":565.0122815398387,"low":565.0122815398387,"close":565.0122815398387,"open":565.0122815398387},{"timestamp":1620384300000,"high":565.0122384439766,"low":565.0122384439766,"close":565.0122384439766,"open":565.0122384439766},{"timestamp":1620385200000,"high":564.9947583554654,"low":564.9947583554654,"close":564.9947583554654,"open":564.9947583554654},{"timestamp":1620386100000,"high":564.7315180958523,"low":564.726251367374,"close":564.726251367374,"open":564.7315180958523},{"timestamp":1620387000000,"high":566.1025337740446,"low":564.5781421341958,"close":566.1025337740446,"open":564.5781421341958}]`); | ||
for (let i = 0; i < parsedCandleArray.length; i++) { | ||
const chunk = parsedCandleArray[i]; | ||
console.log(JSON.stringify(chunk)); | ||
} | ||
/* | ||
// @ts-ignore | ||
@@ -77,2 +53,2 @@ @JSON | ||
const deserializedPlayer = JSON.parse<Player>(serializedPlayer); | ||
console.log("Deserialized Player: " + JSON.stringify(deserializedPlayer));*/ | ||
console.log("Deserialized Player: " + JSON.stringify(deserializedPlayer)); |
{ | ||
"name": "json-as", | ||
"version": "0.5.18", | ||
"version": "0.5.19", | ||
"description": "JSON encoder/decoder for AssemblyScript", | ||
@@ -5,0 +5,0 @@ "types": "assembly/index.ts", |
@@ -1,2 +0,2 @@ | ||
import { getName, toString } from "visitor-as/dist/utils.js"; | ||
import { getName, toString, isStdlib } from "visitor-as/dist/utils.js"; | ||
import { BaseVisitor, SimpleParser } from "visitor-as/dist/index.js"; | ||
@@ -51,3 +51,4 @@ import { Transform } from "assemblyscript/dist/transform.js"; | ||
visitClassDeclaration(node) { | ||
var _a, _b, _c, _d, _e; | ||
var _a; | ||
const className = node.name.text; | ||
if (!((_a = node.decorators) === null || _a === void 0 ? void 0 : _a.length)) | ||
@@ -63,5 +64,2 @@ return; | ||
return; | ||
if (!node.members) { | ||
return; | ||
} | ||
// Prevent from being triggered twice | ||
@@ -73,3 +71,3 @@ for (const member of node.members) { | ||
this.currentClass = { | ||
name: toString(node.name), | ||
name: className, | ||
keys: [], | ||
@@ -84,17 +82,12 @@ values: [], | ||
if (this.currentClass.parent.length > 0) { | ||
const parentSchema = this.schemasList.map((v) => { | ||
if (v.name == this.currentClass.parent) { | ||
return v; | ||
} | ||
}); | ||
if (parentSchema.length > 0 && ((_b = parentSchema[0]) === null || _b === void 0 ? void 0 : _b.encodeStmts)) { | ||
(_c = parentSchema[0]) === null || _c === void 0 ? void 0 : _c.encodeStmts.push(((_d = parentSchema[0]) === null || _d === void 0 ? void 0 : _d.encodeStmts.pop()) + ","); | ||
this.currentClass.encodeStmts.push(...(_e = parentSchema[0]) === null || _e === void 0 ? void 0 : _e.encodeStmts); | ||
const parentSchema = this.schemasList.find((v) => v.name == this.currentClass.parent); | ||
if (parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.encodeStmts) { | ||
parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.encodeStmts.push((parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.encodeStmts.pop()) + ","); | ||
this.currentClass.encodeStmts.push(...parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.encodeStmts); | ||
} | ||
else { | ||
//console.log("Class extends " + this.currentClass.parent + ", but parent class not found. Maybe add the @json decorator over parent class?") | ||
console.error("Class extends " + this.currentClass.parent + ", but parent class not found. Maybe add the @json decorator over parent class?"); | ||
} | ||
} | ||
this.visit(node.members); | ||
// const serializedProp = '__JSON_Serialized: string = "";'; | ||
let serializeFunc = ""; | ||
@@ -124,3 +117,2 @@ if (this.currentClass.encodeStmts.length > 0) { | ||
`; | ||
//console.log(serializeFunc, setKeyFunc) | ||
const serializeMethod = SimpleParser.parseClassMember(serializeFunc, node); | ||
@@ -143,4 +135,4 @@ node.members.push(serializeMethod); | ||
for (const source of parser.sources) { | ||
// Ignore all lib (std lib). Visit everything else. | ||
if (!source.isLibrary && !source.internalPath.startsWith(`~lib/`)) { | ||
// Ignore all lib and std. Visit everything else. | ||
if (!isStdlib(source)) { | ||
transformer.visit(source); | ||
@@ -147,0 +139,0 @@ } |
{ | ||
"name": "@json-as/transform", | ||
"version": "0.5.18", | ||
"version": "0.5.19", | ||
"description": "JSON encoder/decoder for AssemblyScript", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -7,7 +7,3 @@ import { | ||
} from "assemblyscript/dist/assemblyscript"; | ||
import { | ||
ClassDecorator, | ||
registerDecorator, | ||
} from "visitor-as/dist/decorator.js"; | ||
import { getName, toString } from "visitor-as/dist/utils.js"; | ||
import { getName, toString, isStdlib } from "visitor-as/dist/utils.js"; | ||
import { BaseVisitor, SimpleParser } from "visitor-as/dist/index.js"; | ||
@@ -67,2 +63,3 @@ import { Transform } from "assemblyscript/dist/transform.js"; | ||
visitClassDeclaration(node: ClassDeclaration): void { | ||
const className = node.name.text; | ||
if (!node.decorators?.length) return; | ||
@@ -75,5 +72,2 @@ let foundDecorator = false; | ||
if (!foundDecorator) return; | ||
if (!node.members) { | ||
return; | ||
} | ||
@@ -86,3 +80,3 @@ // Prevent from being triggered twice | ||
this.currentClass = { | ||
name: toString(node.name), | ||
name: className, | ||
keys: [], | ||
@@ -96,14 +90,10 @@ values: [], | ||
} | ||
if (this.currentClass.parent.length > 0) { | ||
const parentSchema = this.schemasList.map((v) => { | ||
if (v.name == this.currentClass.parent) { | ||
return v; | ||
} | ||
}); | ||
if (parentSchema.length > 0 && parentSchema[0]?.encodeStmts) { | ||
parentSchema[0]?.encodeStmts.push(parentSchema[0]?.encodeStmts.pop() + ",") | ||
this.currentClass.encodeStmts.push(...parentSchema[0]?.encodeStmts) | ||
const parentSchema = this.schemasList.find((v) => v.name == this.currentClass.parent); | ||
if (parentSchema?.encodeStmts) { | ||
parentSchema?.encodeStmts.push(parentSchema?.encodeStmts.pop() + ","); | ||
this.currentClass.encodeStmts.push(...parentSchema?.encodeStmts); | ||
} else { | ||
//console.log("Class extends " + this.currentClass.parent + ", but parent class not found. Maybe add the @json decorator over parent class?") | ||
console.error("Class extends " + this.currentClass.parent + ", but parent class not found. Maybe add the @json decorator over parent class?"); | ||
} | ||
@@ -114,4 +104,2 @@ } | ||
// const serializedProp = '__JSON_Serialized: string = "";'; | ||
let serializeFunc = ""; | ||
@@ -147,4 +135,2 @@ | ||
//console.log(serializeFunc, setKeyFunc) | ||
const serializeMethod = SimpleParser.parseClassMember(serializeFunc, node); | ||
@@ -173,4 +159,4 @@ node.members.push(serializeMethod); | ||
for (const source of parser.sources) { | ||
// Ignore all lib (std lib). Visit everything else. | ||
if (!source.isLibrary && !source.internalPath.startsWith(`~lib/`)) { | ||
// Ignore all lib and std. Visit everything else. | ||
if (!isStdlib(source)) { | ||
transformer.visit(source); | ||
@@ -177,0 +163,0 @@ } |
25
4.17%64536
-18.22%1444
-5.06%