diff --git a/src/argument.ts b/src/argument.ts index 13f2523a5..58cbd8b3d 100755 --- a/src/argument.ts +++ b/src/argument.ts @@ -203,6 +203,7 @@ export class Argument { } public update(value: string | number | boolean | Filter | keyof typeof Reducer | Object) { + console.log('🚀 ~ file: argument.ts ~ line 206 ~ Argument ~ update ~ value:', value) if (this.argumentType === MarkupArgumentType.SelectFilter) { if (value === 'custom' && (this.value as [Filter, MirScript])[0] !== Filter['custom']) { // the current argument is an input argument and the new value is a subscript argument diff --git a/src/structures.ts b/src/structures.ts index 51679a21a..cd1ed1c3f 100644 --- a/src/structures.ts +++ b/src/structures.ts @@ -88,13 +88,7 @@ export const typeSystem: TypeSystem = { [MapOperatorName.GetMap]: [OperatorCode.MapGetMap, OutputType.Map], [MapOperatorName.GetString]: [OperatorCode.MapGetString, OutputType.String], [MapOperatorName.Keys]: [OperatorCode.MapKeys, OutputType.ArrayString], - [MapOperatorName.valuesArray]: [OperatorCode.MapValuesArray, OutputType.ArrayArray], - //[MapOperatorName.valuesBoolean]: [OperatorCode.MapValuesBoolean, OutputType.ArrayBoolean], - //[MapOperatorName.valuesBytes]: [OperatorCode.MapValuesBytes, OutputType.ArrayBytes], - //[MapOperatorName.valuesFloat]: [OperatorCode.MapValuesFloat, OutputType.ArrayFloat], - //[MapOperatorName.valuesInteger]: [OperatorCode.MapValuesInteger, OutputType.ArrayInteger], - //[MapOperatorName.valuesMap]: [OperatorCode.MapValuesMap, OutputType.ArrayMap], - //[MapOperatorName.valuesString]: [OperatorCode.MapValuesString, OutputType.ArrayString], + [MapOperatorName.values]: [OperatorCode.MapValues, OutputType.ArrayArray], }, [Type.String]: { [StringOperatorName.AsBoolean]: [OperatorCode.StringAsBoolean, OutputType.Boolean], @@ -105,7 +99,7 @@ export const typeSystem: TypeSystem = { [StringOperatorName.Match]: [OperatorCode.StringMatch, OutputType.MatchOutput], [StringOperatorName.ParseJsonArray]: [OperatorCode.StringParseJsonArray, OutputType.Array], [StringOperatorName.ParseJsonMap]: [OperatorCode.StringParseJsonMap, OutputType.Map], - //[StringOperatorName.ParseXml]: [OperatorCode.StringParseXML, OutputType.Map], + [StringOperatorName.ParseXMLMap]: [OperatorCode.StringParseXMLMap, OutputType.Map], [StringOperatorName.ToLowerCase]: [OperatorCode.StringToLowerCase, OutputType.String], [StringOperatorName.ToUpperCase]: [OperatorCode.StringToUpperCase, OutputType.String], }, @@ -792,9 +786,9 @@ export const operatorInfos: OperatorInfos = { outputType: OutputType.ArrayString, description: (i18n: I18n) => () => i18n.t('operator_info_description.map.keys'), }, - [OperatorCode.MapValuesArray]: { + [OperatorCode.MapValues]: { type: Type.Map, - name: MapOperatorName.valuesArray, + name: MapOperatorName.values, arguments: [], outputType: OutputType.ArrayArray, description: (i18n: I18n) => () => descriptions.mapValues(i18n)('Array'), @@ -909,13 +903,13 @@ export const operatorInfos: OperatorInfos = { outputType: OutputType.Map, description: (i18n: I18n) => () => i18n.t('operator_info_description.string.parse_json_map'), }, - /*[OperatorCode.StringParseXML]: { + [OperatorCode.StringParseXMLMap]: { type: Type.String, - name: StringOperatorName.ParseXml, + name: StringOperatorName.ParseXMLMap, arguments: [], outputType: OutputType.Map, description: (i18n: I18n) => () => i18n.t('operator_info_description.string.parse_xml'), - },*/ + }, [OperatorCode.StringToLowerCase]: { type: Type.String, name: StringOperatorName.ToLowerCase, diff --git a/src/types.ts b/src/types.ts index 42741a394..5b61d1099 100644 --- a/src/types.ts +++ b/src/types.ts @@ -71,6 +71,7 @@ export enum Reducer { //deviationAverage = 0x08, //deviationMedian = 0x09, //deviationMaximum = 0x0a, + hashConcatenate = 0x0b, } export enum Filter { @@ -225,8 +226,8 @@ export enum OperatorCode { ArrayGetArray = 0x13, ArrayGetBoolean = 0x14, ArrayGetBytes = 0x15, - ArrayGetInteger = 0x16, - ArrayGetFloat = 0x17, + ArrayGetFloat = 0x16, + ArrayGetInteger = 0x17, ArrayGetMap = 0x18, ArrayGetString = 0x19, ArrayMap = 0x1a, @@ -259,8 +260,8 @@ export enum OperatorCode { FloatAbsolute = 0x50, FloatAsString = 0x51, FloatCeiling = 0x52, - FloatFloor = 0x54, FloatGreaterThan = 0x53, + FloatFloor = 0x54, FloatLessThan = 0x55, FloatModulo = 0x56, FloatMultiply = 0x57, @@ -280,13 +281,7 @@ export enum OperatorCode { MapGetMap = 0x66, MapGetString = 0x67, MapKeys = 0x68, - MapValuesArray = 0x69, - //MapValuesBoolean = 0x6a, - //MapValuesBytes = 0x6b, - //MapValuesFloat = 0x6c, - //MapValuesInteger = 0x6d, - //MapValuesMap = 0x6e, - //MapValuesString = 0x6f, + MapValues = 0x69, StringAsBoolean = 0x70, //StringAsBytes = 0x71, @@ -296,7 +291,7 @@ export enum OperatorCode { StringMatch = 0x75, StringParseJsonArray = 0x76, StringParseJsonMap = 0x77, - //StringParseXML = 0x78, + StringParseXMLMap = 0x78, StringToLowerCase = 0x79, StringToUpperCase = 0x7a, } @@ -327,6 +322,7 @@ export type MirArgument = | [Filter, number] | [Filter, string] | [Filter, boolean] + // TODO: Should [Filter, MirScript] be [MirScript]? | [Filter, MirScript] | MirScript | Reducer @@ -483,13 +479,7 @@ export enum MapOperatorName { GetMap = 'getMap', GetString = 'getString', Keys = 'keys', - valuesArray = 'valuesAsArray', - //valuesBoolean = 'valuesAsBoolean', - //valuesBytes = 'valuesAsBytes', - //valuesInteger = 'valuesAsInteger', - //valuesFloat = 'valuesAsFloat', - //valuesMap = 'valuesAsMap', - //valuesString = 'valuesAsString', + values = 'values', } export enum StringOperatorName { @@ -501,7 +491,7 @@ export enum StringOperatorName { Match = 'match', ParseJsonArray = 'parseJSONArray', ParseJsonMap = 'parseJSONMap', - //ParseXml = 'parseXML', + ParseXMLMap = 'parseXMLMap', ToLowerCase = 'toLowerCase', ToUpperCase = 'toUpperCase', } diff --git a/src/utils.ts b/src/utils.ts index 2cb476485..63487d849 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -139,7 +139,10 @@ export function getDefaultMirOperatorByType(type: Type): MirOperator { export function getMirOperatorInfo( operator: MirOperator -): { code: OperatorCode; args: Array } { +): { + code: OperatorCode + args: Array +} { return Array.isArray(operator) ? { code: operator[0] as OperatorCode, diff --git a/test/src/argument.spec.ts b/test/src/argument.spec.ts index 8f07339b6..0422c78f5 100644 --- a/test/src/argument.spec.ts +++ b/test/src/argument.spec.ts @@ -308,6 +308,12 @@ describe('Argument methods', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', @@ -370,7 +376,7 @@ describe('Argument methods', () => { }, { hierarchicalType: 'operatorOption', - label: 'MapValuesArray', + label: 'MapValues', markupType: 'option', outputType: 'arrayArray', }, @@ -498,6 +504,12 @@ describe('Argument methods', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', @@ -854,6 +866,12 @@ describe('Argument methods', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', @@ -916,7 +934,7 @@ describe('Argument methods', () => { }, { hierarchicalType: 'operatorOption', - label: 'MapValuesArray', + label: 'MapValues', markupType: 'option', outputType: 'arrayArray', }, @@ -1044,6 +1062,12 @@ describe('Argument methods', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', @@ -1117,6 +1141,12 @@ describe('Argument methods', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', diff --git a/test/src/operator.spec.ts b/test/src/operator.spec.ts index 579ac61fc..04f5979ee 100644 --- a/test/src/operator.spec.ts +++ b/test/src/operator.spec.ts @@ -347,6 +347,12 @@ describe('Operator methods', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', @@ -409,7 +415,7 @@ describe('Operator methods', () => { }, { hierarchicalType: 'operatorOption', - label: 'MapValuesArray', + label: 'MapValues', markupType: 'option', outputType: 'arrayArray', }, @@ -695,6 +701,12 @@ describe('Operator methods', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', @@ -757,7 +769,7 @@ describe('Operator methods', () => { }, { hierarchicalType: 'operatorOption', - label: 'MapValuesArray', + label: 'MapValues', markupType: 'option', outputType: 'arrayArray', }, @@ -1122,6 +1134,23 @@ describe('Operator methods', () => { expect(result).toStrictEqual(expected) }) + + it('custom filter', () => { + const op: MirOperator = [ + OperatorCode.ArrayFilter, + [ + [OperatorCode.MapGetString, 'symbol'], + [OperatorCode.StringMatch, { 'GLINT-USDT': true }, false], + ], + ] + const context: Context = { cache: new Cache(), i18n: new I18n() } + const operator = new Operator(context, 0, OutputType.Array, op, { emit: () => {} }) + + const result = operator.getMir() + const expected = op + + expect(result).toStrictEqual(expected) + }) }) describe('update', () => { diff --git a/test/src/radon.spec.ts b/test/src/radon.spec.ts index 161ddf944..91f38a577 100755 --- a/test/src/radon.spec.ts +++ b/test/src/radon.spec.ts @@ -851,6 +851,12 @@ describe('Radon', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', @@ -931,7 +937,7 @@ describe('Radon', () => { }, { hierarchicalType: 'operatorOption', - label: 'MapValuesArray', + label: 'MapValues', markupType: 'option', outputType: 'arrayArray', }, @@ -1291,6 +1297,12 @@ describe('Radon', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', @@ -1353,7 +1365,7 @@ describe('Radon', () => { }, { hierarchicalType: 'operatorOption', - label: 'MapValuesArray', + label: 'MapValues', markupType: 'option', outputType: 'arrayArray', }, @@ -1885,6 +1897,12 @@ describe('Radon', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', @@ -1947,7 +1965,7 @@ describe('Radon', () => { }, { hierarchicalType: 'operatorOption', - label: 'MapValuesArray', + label: 'MapValues', markupType: 'option', outputType: 'arrayArray', }, @@ -2343,6 +2361,12 @@ describe('Radon', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', @@ -2405,7 +2429,7 @@ describe('Radon', () => { }, { hierarchicalType: 'operatorOption', - label: 'MapValuesArray', + label: 'MapValues', markupType: 'option', outputType: 'arrayArray', }, @@ -2554,6 +2578,12 @@ describe('Radon', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', @@ -2638,6 +2668,12 @@ describe('Radon', () => { markupType: 'option', outputType: 'map', }, + { + hierarchicalType: 'operatorOption', + label: 'StringParseXMLMap', + markupType: 'option', + outputType: 'map', + }, { hierarchicalType: 'operatorOption', label: 'StringToLowerCase', @@ -3250,7 +3286,7 @@ describe('Radon', () => { [[0x64, 'price']], ], [ - 23, // get + 0x16, // get '0', ], ],