Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom filter #84

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 7 additions & 13 deletions src/structures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
},
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 9 additions & 19 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export enum Reducer {
//deviationAverage = 0x08,
//deviationMedian = 0x09,
//deviationMaximum = 0x0a,
hashConcatenate = 0x0b,
}

export enum Filter {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -296,7 +291,7 @@ export enum OperatorCode {
StringMatch = 0x75,
StringParseJsonArray = 0x76,
StringParseJsonMap = 0x77,
//StringParseXML = 0x78,
StringParseXMLMap = 0x78,
StringToLowerCase = 0x79,
StringToUpperCase = 0x7a,
}
Expand Down Expand Up @@ -327,6 +322,7 @@ export type MirArgument =
| [Filter, number]
| [Filter, string]
| [Filter, boolean]
// TODO: Should [Filter, MirScript] be [MirScript]?
| [Filter, MirScript]
| MirScript
| Reducer
Expand Down Expand Up @@ -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 {
Expand All @@ -501,7 +491,7 @@ export enum StringOperatorName {
Match = 'match',
ParseJsonArray = 'parseJSONArray',
ParseJsonMap = 'parseJSONMap',
//ParseXml = 'parseXML',
ParseXMLMap = 'parseXMLMap',
ToLowerCase = 'toLowerCase',
ToUpperCase = 'toUpperCase',
}
Expand Down
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ export function getDefaultMirOperatorByType(type: Type): MirOperator {

export function getMirOperatorInfo(
operator: MirOperator
): { code: OperatorCode; args: Array<MirArgument> } {
): {
code: OperatorCode
args: Array<MirArgument>
} {
return Array.isArray(operator)
? {
code: operator[0] as OperatorCode,
Expand Down
34 changes: 32 additions & 2 deletions test/src/argument.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ describe('Argument methods', () => {
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringParseXMLMap',
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringToLowerCase',
Expand Down Expand Up @@ -370,7 +376,7 @@ describe('Argument methods', () => {
},
{
hierarchicalType: 'operatorOption',
label: 'MapValuesArray',
label: 'MapValues',
markupType: 'option',
outputType: 'arrayArray',
},
Expand Down Expand Up @@ -498,6 +504,12 @@ describe('Argument methods', () => {
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringParseXMLMap',
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringToLowerCase',
Expand Down Expand Up @@ -854,6 +866,12 @@ describe('Argument methods', () => {
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringParseXMLMap',
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringToLowerCase',
Expand Down Expand Up @@ -916,7 +934,7 @@ describe('Argument methods', () => {
},
{
hierarchicalType: 'operatorOption',
label: 'MapValuesArray',
label: 'MapValues',
markupType: 'option',
outputType: 'arrayArray',
},
Expand Down Expand Up @@ -1044,6 +1062,12 @@ describe('Argument methods', () => {
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringParseXMLMap',
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringToLowerCase',
Expand Down Expand Up @@ -1117,6 +1141,12 @@ describe('Argument methods', () => {
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringParseXMLMap',
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringToLowerCase',
Expand Down
33 changes: 31 additions & 2 deletions test/src/operator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ describe('Operator methods', () => {
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringParseXMLMap',
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringToLowerCase',
Expand Down Expand Up @@ -409,7 +415,7 @@ describe('Operator methods', () => {
},
{
hierarchicalType: 'operatorOption',
label: 'MapValuesArray',
label: 'MapValues',
markupType: 'option',
outputType: 'arrayArray',
},
Expand Down Expand Up @@ -695,6 +701,12 @@ describe('Operator methods', () => {
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringParseXMLMap',
markupType: 'option',
outputType: 'map',
},
{
hierarchicalType: 'operatorOption',
label: 'StringToLowerCase',
Expand Down Expand Up @@ -757,7 +769,7 @@ describe('Operator methods', () => {
},
{
hierarchicalType: 'operatorOption',
label: 'MapValuesArray',
label: 'MapValues',
markupType: 'option',
outputType: 'arrayArray',
},
Expand Down Expand Up @@ -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', () => {
Expand Down
Loading