@taquito/michelson-encoder
Advanced tools
Comparing version 20.0.0-beta.0 to 20.0.0-beta.1
@@ -25,5 +25,5 @@ "use strict"; | ||
*/ | ||
function createToken(val, idx) { | ||
function createToken(val, idx, parentTokenType) { | ||
if (Array.isArray(val)) { | ||
return new pair_1.PairToken(val, idx, createToken); | ||
return new pair_1.PairToken(val, idx, createToken, parentTokenType); | ||
} | ||
@@ -34,4 +34,4 @@ const t = tokens_1.tokens.find((x) => x.prim === val.prim); | ||
} | ||
return new t(val, idx, createToken); | ||
return new t(val, idx, createToken, parentTokenType); | ||
} | ||
exports.createToken = createToken; |
@@ -19,11 +19,12 @@ "use strict"; | ||
class OrToken extends token_1.ComparableToken { | ||
constructor(val, idx, fac) { | ||
super(val, idx, fac); | ||
constructor(val, idx, fac, parentTokenType) { | ||
super(val, idx, fac, parentTokenType); | ||
this.val = val; | ||
this.idx = idx; | ||
this.fac = fac; | ||
this.parentTokenType = parentTokenType; | ||
} | ||
Encode(args) { | ||
const label = args[args.length - 1]; | ||
const leftToken = this.createToken(this.val.args[0], this.idx); | ||
const leftToken = this.createToken(this.val.args[0], this.getIdxForChildren(), 'Or'); | ||
let keyCount = 1; | ||
@@ -33,3 +34,3 @@ if (leftToken instanceof OrToken) { | ||
} | ||
const rightToken = this.createToken(this.val.args[1], this.idx + keyCount); | ||
const rightToken = this.createToken(this.val.args[1], this.getIdxForChildren() + keyCount, 'Or'); | ||
if (String(leftToken.annot()) === String(label) && !(leftToken instanceof OrToken)) { | ||
@@ -60,3 +61,3 @@ args.pop(); | ||
ExtractSignature() { | ||
const leftToken = this.createToken(this.val.args[0], this.idx); | ||
const leftToken = this.createToken(this.val.args[0], this.getIdxForChildren(), 'Or'); | ||
let keyCount = 1; | ||
@@ -66,3 +67,3 @@ if (leftToken instanceof OrToken) { | ||
} | ||
const rightToken = this.createToken(this.val.args[1], this.idx + keyCount); | ||
const rightToken = this.createToken(this.val.args[1], this.getIdxForChildren() + keyCount, 'Or'); | ||
const newSig = []; | ||
@@ -93,3 +94,3 @@ if (leftToken instanceof OrToken) { | ||
const label = Object.keys(args)[0]; | ||
const leftToken = this.createToken(this.val.args[0], this.idx); | ||
const leftToken = this.createToken(this.val.args[0], this.getIdxForChildren(), 'Or'); | ||
let keyCount = 1; | ||
@@ -99,3 +100,3 @@ if (leftToken instanceof OrToken) { | ||
} | ||
const rightToken = this.createToken(this.val.args[1], this.idx + keyCount); | ||
const rightToken = this.createToken(this.val.args[1], this.getIdxForChildren() + keyCount, 'Or'); | ||
if (String(leftToken.annot()) === String(label) && !(leftToken instanceof OrToken)) { | ||
@@ -138,3 +139,3 @@ return { prim: 'Left', args: [leftToken.EncodeObject(args[label], semantic)] }; | ||
Execute(val, semantics) { | ||
const leftToken = this.createToken(this.val.args[0], this.idx); | ||
const leftToken = this.createToken(this.val.args[0], this.getIdxForChildren(), 'Or'); | ||
let keyCount = 1; | ||
@@ -144,3 +145,3 @@ if (leftToken instanceof OrToken) { | ||
} | ||
const rightToken = this.createToken(this.val.args[1], this.idx + keyCount); | ||
const rightToken = this.createToken(this.val.args[1], this.getIdxForChildren() + keyCount, 'Or'); | ||
if (val.prim === 'Right') { | ||
@@ -169,3 +170,3 @@ if (rightToken instanceof OrToken) { | ||
traversal(getLeftValue, getRightValue, concat) { | ||
const leftToken = this.createToken(this.val.args[0], this.idx); | ||
const leftToken = this.createToken(this.val.args[0], this.getIdxForChildren(), 'Or'); | ||
let keyCount = 1; | ||
@@ -180,3 +181,3 @@ let leftValue; | ||
} | ||
const rightToken = this.createToken(this.val.args[1], this.idx + keyCount); | ||
const rightToken = this.createToken(this.val.args[1], this.getIdxForChildren() + keyCount, 'Or'); | ||
let rightValue; | ||
@@ -220,3 +221,3 @@ if (rightToken instanceof OrToken) { | ||
findToken(label) { | ||
const leftToken = this.createToken(this.val.args[0], this.idx); | ||
const leftToken = this.createToken(this.val.args[0], this.getIdxForChildren(), 'Or'); | ||
let keyCount = 1; | ||
@@ -226,3 +227,3 @@ if (leftToken instanceof OrToken) { | ||
} | ||
const rightToken = this.createToken(this.val.args[1], this.idx + keyCount); | ||
const rightToken = this.createToken(this.val.args[1], this.getIdxForChildren() + keyCount, 'Or'); | ||
if (String(leftToken.annot()) === String(label) && | ||
@@ -285,4 +286,10 @@ !(leftToken instanceof OrToken) && | ||
} | ||
getIdxForChildren() { | ||
if (token_1.Token.fieldNumberingStrategy === 'Legacy') { | ||
return this.idx; | ||
} | ||
return this.parentTokenType === 'Or' ? this.idx : 0; | ||
} | ||
} | ||
exports.OrToken = OrToken; | ||
OrToken.prim = 'or'; |
@@ -59,3 +59,3 @@ "use strict"; | ||
class PairToken extends token_1.ComparableToken { | ||
constructor(val, idx, fac) { | ||
constructor(val, idx, fac, parentTokenType) { | ||
super(Array.isArray(val) | ||
@@ -71,3 +71,3 @@ ? { | ||
args: val, | ||
}, idx, fac); | ||
}, idx, fac, parentTokenType); | ||
} | ||
@@ -81,3 +81,3 @@ args() { | ||
return this.args().map((a) => { | ||
const tok = this.createToken(a, this.idx + cnt); | ||
const tok = this.createToken(a, this.getIdxForChildren() + cnt, 'Pair'); | ||
if (tok instanceof PairToken) { | ||
@@ -100,3 +100,3 @@ cnt += Object.keys(tok.ExtractSchema()).length; | ||
const args = this.args(); | ||
const leftToken = this.createToken(args[0], this.idx); | ||
const leftToken = this.createToken(args[0], this.getIdxForChildren(), 'Pair'); | ||
let keyCount = 1; | ||
@@ -106,3 +106,3 @@ if (leftToken instanceof or_1.OrToken) { | ||
} | ||
const rightToken = this.createToken(args[1], this.idx + keyCount); | ||
const rightToken = this.createToken(args[1], this.getIdxForChildren() + keyCount, 'Pair'); | ||
const newSig = []; | ||
@@ -151,3 +151,3 @@ for (const leftSig of leftToken.ExtractSignature()) { | ||
const args = this.args(); | ||
const leftToken = this.createToken(args[0], this.idx); | ||
const leftToken = this.createToken(args[0], this.getIdxForChildren(), 'Pair'); | ||
let keyCount = 1; | ||
@@ -164,3 +164,3 @@ let leftValue; | ||
} | ||
const rightToken = this.createToken(args[1], this.idx + keyCount); | ||
const rightToken = this.createToken(args[1], this.getIdxForChildren() + keyCount, 'Pair'); | ||
let rightValue; | ||
@@ -236,4 +236,10 @@ if (rightToken instanceof PairToken && !rightToken.hasAnnotations()) { | ||
} | ||
getIdxForChildren() { | ||
if (token_1.Token.fieldNumberingStrategy === 'Legacy') { | ||
return this.idx; | ||
} | ||
return this.parentTokenType === 'Pair' ? this.idx : 0; | ||
} | ||
} | ||
exports.PairToken = PairToken; | ||
PairToken.prim = 'pair'; |
@@ -22,6 +22,19 @@ "use strict"; | ||
class Token { | ||
constructor(val, idx, fac) { | ||
/** | ||
* @description Gets the strategy used for field numbering in Token execute/encode/decode to convert Michelson values to/from javascript objects, returns a value of type {@link FieldNumberingStrategy} that controls how field numbers are calculated | ||
*/ | ||
static get fieldNumberingStrategy() { | ||
return Token._fieldNumberingStrategy; | ||
} | ||
/** | ||
* @description Sets the strategy used for field numbering in Token execute/encode/decode to convert Michelson values to/from javascript objects, accepts a value of type {@link FieldNumberingStrategy} that controls how field numbers are calculated | ||
*/ | ||
static set fieldNumberingStrategy(value) { | ||
Token._fieldNumberingStrategy = value; | ||
} | ||
constructor(val, idx, fac, parentTokenType) { | ||
this.val = val; | ||
this.idx = idx; | ||
this.fac = fac; | ||
this.parentTokenType = parentTokenType; | ||
this.createToken = this.fac; | ||
@@ -82,2 +95,3 @@ } | ||
exports.Token = Token; | ||
Token._fieldNumberingStrategy = 'Latest'; | ||
class ComparableToken extends Token { | ||
@@ -84,0 +98,0 @@ compare(o1, o2) { |
@@ -6,4 +6,4 @@ "use strict"; | ||
exports.VERSION = { | ||
"commitHash": "0ef631853ccfda5c5faed584f16069f34085817e", | ||
"version": "20.0.0-beta.0" | ||
"commitHash": "4c6e079465fdb978c1627dfdcced0435c9ef87fc", | ||
"version": "20.0.0-beta.1" | ||
}; |
@@ -17,2 +17,2 @@ /** | ||
export { VERSION } from './version'; | ||
export { Token } from './tokens/token'; | ||
export { FieldNumberingStrategy, Token } from './tokens/token'; |
@@ -18,2 +18,2 @@ import { Token } from './token'; | ||
*/ | ||
export declare function createToken(val: any, idx: number): Token; | ||
export declare function createToken(val: any, idx: number, parentTokenType?: 'Or' | 'Pair' | 'Other' | undefined): Token; |
@@ -21,2 +21,3 @@ import { OrTokenSchema } from '../schema/types'; | ||
protected fac: TokenFactory; | ||
protected parentTokenType?: "Or" | "Pair" | "Other" | undefined; | ||
static prim: 'or'; | ||
@@ -27,3 +28,3 @@ constructor(val: { | ||
annots: any[]; | ||
}, idx: number, fac: TokenFactory); | ||
}, idx: number, fac: TokenFactory, parentTokenType?: "Or" | "Pair" | "Other" | undefined); | ||
Encode(args: any[]): any; | ||
@@ -58,2 +59,3 @@ ExtractSignature(): any; | ||
findAndReturnTokens(tokenToFind: string, tokens: Token[]): Token[]; | ||
protected getIdxForChildren(): number; | ||
} |
@@ -26,3 +26,3 @@ import { Token, TokenFactory, Semantic, ComparableToken, SemanticEncoding } from './token'; | ||
static prim: 'pair'; | ||
constructor(val: MichelsonV1Expression, idx: number, fac: TokenFactory); | ||
constructor(val: MichelsonV1Expression, idx: number, fac: TokenFactory, parentTokenType?: 'Or' | 'Pair' | 'Other' | undefined); | ||
private args; | ||
@@ -55,2 +55,3 @@ private tokens; | ||
findAndReturnTokens(tokenToFind: string, tokens: Token[]): Token[]; | ||
protected getIdxForChildren(): number; | ||
} |
@@ -14,3 +14,3 @@ import { MichelsonV1Expression, MichelsonV1ExpressionExtended } from '@taquito/rpc'; | ||
} | ||
export type TokenFactory = (val: any, idx: number) => Token; | ||
export type TokenFactory = (val: any, idx: number, parentTokenType?: 'Or' | 'Pair' | 'Other') => Token; | ||
export interface Semantic { | ||
@@ -22,2 +22,9 @@ [key: string]: (value: MichelsonV1Expression, schema: MichelsonV1Expression) => any; | ||
} | ||
/** | ||
* @description Possible strategies for mapping between javascript classes and Michelson values | ||
* Legacy: The old behaviour: { annot1: 'some value', annot2: 'other Value', annot3: { 2: 'yet another value', 3: 'also some value' }} | ||
* ResetFieldNumbersInNestedObjects: { annot1: 'some value', annot2: 'other Value', annot3: { 0: 'yet another value', 1: 'also some value' }} | ||
* Latest: This will include new changes as we might implement in the future. This is the suggested value if it does not break your code | ||
*/ | ||
export type FieldNumberingStrategy = 'Legacy' | 'ResetFieldNumbersInNestedObjects' | 'Latest'; | ||
export declare abstract class Token { | ||
@@ -27,3 +34,13 @@ protected val: MichelsonV1ExpressionExtended; | ||
protected fac: TokenFactory; | ||
constructor(val: MichelsonV1ExpressionExtended, idx: number, fac: TokenFactory); | ||
protected parentTokenType?: "Or" | "Pair" | "Other" | undefined; | ||
private static _fieldNumberingStrategy; | ||
/** | ||
* @description Gets the strategy used for field numbering in Token execute/encode/decode to convert Michelson values to/from javascript objects, returns a value of type {@link FieldNumberingStrategy} that controls how field numbers are calculated | ||
*/ | ||
static get fieldNumberingStrategy(): FieldNumberingStrategy; | ||
/** | ||
* @description Sets the strategy used for field numbering in Token execute/encode/decode to convert Michelson values to/from javascript objects, accepts a value of type {@link FieldNumberingStrategy} that controls how field numbers are calculated | ||
*/ | ||
static set fieldNumberingStrategy(value: FieldNumberingStrategy); | ||
constructor(val: MichelsonV1ExpressionExtended, idx: number, fac: TokenFactory, parentTokenType?: "Or" | "Pair" | "Other" | undefined); | ||
protected typeWithoutAnnotations(): Omit<MichelsonV1ExpressionExtended, "annots">; | ||
@@ -30,0 +47,0 @@ annot(): string; |
{ | ||
"name": "@taquito/michelson-encoder", | ||
"version": "20.0.0-beta.0", | ||
"version": "20.0.0-beta.1", | ||
"description": "converts michelson data and types into convenient JS/TS objects", | ||
@@ -70,5 +70,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@taquito/core": "^20.0.0-beta.0", | ||
"@taquito/rpc": "^20.0.0-beta.0", | ||
"@taquito/utils": "^20.0.0-beta.0", | ||
"@taquito/core": "^20.0.0-beta.1", | ||
"@taquito/rpc": "^20.0.0-beta.1", | ||
"@taquito/utils": "^20.0.0-beta.1", | ||
"bignumber.js": "^9.1.2", | ||
@@ -104,3 +104,3 @@ "fast-json-stable-stringify": "^2.1.0" | ||
}, | ||
"gitHead": "88980709574468fad5e4e7d63d34e1d71accf550" | ||
"gitHead": "55491dbb67866d3196843b167ca9303f803b1a99" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
568458
16145
Updated@taquito/core@^20.0.0-beta.1
Updated@taquito/rpc@^20.0.0-beta.1