From 7c3ade99287906640ebb4c6dd87a2cd6d4558464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 14 Nov 2023 10:18:13 +0100 Subject: [PATCH 1/6] feat: add support to HTTP/HEAD --- src/constants.ts | 1 + src/types.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/constants.ts b/src/constants.ts index ec681098b..ef37d92e4 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -6,6 +6,7 @@ export const DEFAULT_SCRIPT_FIRST_TYPE = OutputType.String export const KIND_OPTIONS = [Kind.HttpGet, Kind.RNG, Kind.HttpPost] export const CONTENT_TYPE_OPTIONS = { [Kind.HttpGet]: 'JSON API', + [Kind.HttpHead]: 'JSON API', [Kind.HttpPost]: 'JSON API', [Kind.RNG]: 'Binary file', } diff --git a/src/types.ts b/src/types.ts index 6795fa8f0..1e5888b84 100644 --- a/src/types.ts +++ b/src/types.ts @@ -220,6 +220,7 @@ export type KindOptions = Array export enum Kind { HttpGet = 'HTTP-GET', HttpPost = 'HTTP-POST', + HttpHead = 'HTTP-HEAD', RNG = 'RNG', } From 64b06c255072e58395720fee3e8ef9fee6fd3118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 14 Nov 2023 10:20:51 +0100 Subject: [PATCH 2/6] feat: add support to StringReplace --- src/structures.ts | 22 ++++++++++++++++++++++ src/types.ts | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/structures.ts b/src/structures.ts index 34da13e4a..bfbb08513 100644 --- a/src/structures.ts +++ b/src/structures.ts @@ -102,6 +102,7 @@ export const typeSystem: TypeSystem = { [StringOperatorName.ParseXmlMap]: [OperatorCode.StringParseXmlMap, OutputType.Map], [StringOperatorName.ToLowerCase]: [OperatorCode.StringToLowerCase, OutputType.String], [StringOperatorName.ToUpperCase]: [OperatorCode.StringToUpperCase, OutputType.String], + [StringOperatorName.Replace]: [OperatorCode.StringReplace, OutputType.String], }, } @@ -947,6 +948,27 @@ export const operatorInfos: OperatorInfos = { outputType: OutputType.String, description: (i18n: I18n) => () => i18n.t('operator_info_description.string.to_upper_case'), }, + [OperatorCode.StringReplace]: { + type: Type.String, + name: StringOperatorName.Replace, + arguments: [ + { + name: 'pattern', + optional: false, + type: MirArgumentType.String, + }, + { + name: 'replacement', + optional: false, + type: MirArgumentType.String, + }, + ], + outputType: OutputType.String, + description: + (i18n: I18n) => + (pattern: string = '', replacement: string = '') => + i18n.t('operator_info_description.string.replace', { pattern, replacement }), + }, } export class Cache { diff --git a/src/types.ts b/src/types.ts index 1e5888b84..a98a75fb7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -299,6 +299,7 @@ export enum OperatorCode { StringParseXmlMap = 0x78, StringToLowerCase = 0x79, StringToUpperCase = 0x7a, + StringReplace = 0x7b, } export enum MirArgumentType { @@ -500,6 +501,7 @@ export enum StringOperatorName { ParseXmlMap = 'parseXMLMap', ToLowerCase = 'toLowerCase', ToUpperCase = 'toUpperCase', + Replace = 'replace', } export type OperatorName = From e2c2e91086a5479f95e9d0c64fb4070061e446b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 14 Nov 2023 10:21:52 +0100 Subject: [PATCH 3/6] feat: add support to StringSlice --- src/structures.ts | 22 ++++++++++++++++++++++ src/types.ts | 1 + 2 files changed, 23 insertions(+) diff --git a/src/structures.ts b/src/structures.ts index bfbb08513..328efedf7 100644 --- a/src/structures.ts +++ b/src/structures.ts @@ -103,6 +103,7 @@ export const typeSystem: TypeSystem = { [StringOperatorName.ToLowerCase]: [OperatorCode.StringToLowerCase, OutputType.String], [StringOperatorName.ToUpperCase]: [OperatorCode.StringToUpperCase, OutputType.String], [StringOperatorName.Replace]: [OperatorCode.StringReplace, OutputType.String], + [StringOperatorName.Slice]: [OperatorCode.StringSlice, OutputType.String], }, } @@ -969,6 +970,27 @@ export const operatorInfos: OperatorInfos = { (pattern: string = '', replacement: string = '') => i18n.t('operator_info_description.string.replace', { pattern, replacement }), }, + [OperatorCode.StringSlice]: { + type: Type.String, + name: StringOperatorName.Slice, + arguments: [ + { + name: 'startIndex', + optional: false, + type: MirArgumentType.Integer, + }, + { + name: 'endIndex', + optional: true, + type: MirArgumentType.Integer, + }, + ], + outputType: OutputType.String, + description: + (i18n: I18n) => + (startIndex: number = 0, endIndex: number) => + i18n.t('operator_info_description.string.slice', { startIndex, endIndex }), + }, } export class Cache { diff --git a/src/types.ts b/src/types.ts index a98a75fb7..e3825c639 100644 --- a/src/types.ts +++ b/src/types.ts @@ -502,6 +502,7 @@ export enum StringOperatorName { ToLowerCase = 'toLowerCase', ToUpperCase = 'toUpperCase', Replace = 'replace', + Slice = 'slice', } export type OperatorName = From 0314faa61a5c82a269e307b2b8709a19f0fe6ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 14 Nov 2023 10:23:56 +0100 Subject: [PATCH 4/6] feat: add support to StringSplit --- src/structures.ts | 17 +++++++++++++++++ src/types.ts | 3 +++ 2 files changed, 20 insertions(+) diff --git a/src/structures.ts b/src/structures.ts index 328efedf7..44b631d14 100644 --- a/src/structures.ts +++ b/src/structures.ts @@ -104,6 +104,7 @@ export const typeSystem: TypeSystem = { [StringOperatorName.ToUpperCase]: [OperatorCode.StringToUpperCase, OutputType.String], [StringOperatorName.Replace]: [OperatorCode.StringReplace, OutputType.String], [StringOperatorName.Slice]: [OperatorCode.StringSlice, OutputType.String], + [StringOperatorName.Split]: [OperatorCode.StringSplit, OutputType.String], }, } @@ -991,6 +992,22 @@ export const operatorInfos: OperatorInfos = { (startIndex: number = 0, endIndex: number) => i18n.t('operator_info_description.string.slice', { startIndex, endIndex }), }, + [OperatorCode.StringSplit]: { + type: Type.String, + name: StringOperatorName.Split, + arguments: [ + { + name: 'regex', + optional: true, + type: MirArgumentType.String, + }, + ], + outputType: OutputType.ArrayString, + description: + (i18n: I18n) => + (regex: string = "\r") => + i18n.t('operator_info_description.string.split', { regex }), + }, } export class Cache { diff --git a/src/types.ts b/src/types.ts index e3825c639..aceafe77c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -300,6 +300,8 @@ export enum OperatorCode { StringToLowerCase = 0x79, StringToUpperCase = 0x7a, StringReplace = 0x7b, + StringSlice = 0x7c, + StringSplit = 0x7d, } export enum MirArgumentType { @@ -503,6 +505,7 @@ export enum StringOperatorName { ToUpperCase = 'toUpperCase', Replace = 'replace', Slice = 'slice', + Split = 'split', } export type OperatorName = From 47c84fba573c4cccdbc9d0bed373f171f1340486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 14 Nov 2023 10:24:27 +0100 Subject: [PATCH 5/6] feat: add support to ArrayJoin --- src/structures.ts | 16 ++++++++-------- src/types.ts | 5 +++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/structures.ts b/src/structures.ts index 44b631d14..de9edb4fa 100644 --- a/src/structures.ts +++ b/src/structures.ts @@ -25,7 +25,7 @@ export const typeSystem: TypeSystem = { [Type.Array]: { [ArrayOperatorName.Count]: [OperatorCode.ArrayCount, OutputType.Integer], [ArrayOperatorName.Filter]: [OperatorCode.ArrayFilter, OutputType.Same], - //[ArrayOperatorName.Flatten]: [OperatorCode.ArrayFlatten, OutputType.Array], + [ArrayOperatorName.Join]: [OperatorCode.ArrayJoin, OutputType.JoinOutput], [ArrayOperatorName.GetArray]: [OperatorCode.ArrayGetArray, OutputType.Array], [ArrayOperatorName.GetBoolean]: [OperatorCode.ArrayGetBoolean, OutputType.Boolean], [ArrayOperatorName.GetBytes]: [OperatorCode.ArrayGetBytes, OutputType.Bytes], @@ -172,20 +172,20 @@ export const operatorInfos: OperatorInfos = { (filter: string = 'filter') => i18n.t('operator_info_description.array.filter', { filter }), }, - /*[OperatorCode.ArrayFlatten]: { + [OperatorCode.ArrayJoin]: { type: Type.Array, - name: ArrayOperatorName.Flatten, + name: ArrayOperatorName.Join, arguments: [ { - name: 'depth', + name: 'separator', optional: true, - type: MirArgumentType.Integer, + type: MirArgumentType.String, }, ], outputType: OutputType.Inner, - description: (i18n: I18n) => (depth: string = 'depth') => - i18n.t('operator_info_description.array.flatten', { depth }), - },*/ + description: (i18n: I18n) => (separator: string = '') => + i18n.t('operator_info_description.array.join', { separator }), + }, [OperatorCode.ArrayGetArray]: { type: Type.Array, name: ArrayOperatorName.GetArray, diff --git a/src/types.ts b/src/types.ts index aceafe77c..12fa7cd10 100644 --- a/src/types.ts +++ b/src/types.ts @@ -118,6 +118,7 @@ export enum OutputType { Same = 'same', String = 'string', SubscriptOutput = 'subscriptOutput', + JoinOutput = 'joinOutput', } export enum MarkupHierarchicalType { @@ -227,7 +228,7 @@ export enum Kind { export enum OperatorCode { ArrayCount = 0x10, ArrayFilter = 0x11, - //ArrayFlatten = 0x12, + ArrayJoin = 0x12, ArrayGetArray = 0x13, ArrayGetBoolean = 0x14, ArrayGetBytes = 0x15, @@ -420,7 +421,7 @@ export type OperatorInfos = { export enum ArrayOperatorName { Count = 'count', Filter = 'filter', - //Flatten = 'flatten', + Join = 'join', GetArray = 'getArray', GetBoolean = 'getBoolean', GetBytes = 'getBytes', From 2aa32cf89fc1e9cf44f6b9250dea51767cafd24d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Tue, 14 Nov 2023 18:16:05 +0100 Subject: [PATCH 6/6] fix: drilling bytes operators with no arguments --- src/argument.ts | 14 +++++++------- src/utils.ts | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/argument.ts b/src/argument.ts index 13f2523a5..6e974509a 100755 --- a/src/argument.ts +++ b/src/argument.ts @@ -39,13 +39,13 @@ export class Argument { this.context = context this.value = argument if ( - this.argumentInfo.type === MirArgumentType.Boolean || - this.argumentInfo.type === MirArgumentType.Float || - this.argumentInfo.type === MirArgumentType.Integer || - this.argumentInfo.type === MirArgumentType.String + this.argumentInfo?.type === MirArgumentType.Boolean || + this.argumentInfo?.type === MirArgumentType.Float || + this.argumentInfo?.type === MirArgumentType.Integer || + this.argumentInfo?.type === MirArgumentType.String ) { this.argument = null - } else if (this.argumentInfo.type === MirArgumentType.FilterFunction) { + } else if (this.argumentInfo?.type === MirArgumentType.FilterFunction) { // Check if it's custom filter to know if contains a subscript or a filter function if (Array.isArray(argument) && Array.isArray(argument[1])) { this.argument = new Argument( @@ -60,13 +60,13 @@ export class Argument { (argument as [Filter, boolean | string | number])[1] ) } - } else if (this.argumentInfo.type === MirArgumentType.ReducerFunction) { + } else if (this.argumentInfo?.type === MirArgumentType.ReducerFunction) { this.argument = new Argument( this.context, { name: 'by', optional: false, type: MirArgumentType.String }, argument as Reducer ) - } else if (this.argumentInfo.type === MirArgumentType.Subscript) { + } else if (this.argumentInfo?.type === MirArgumentType.Subscript) { this.argument = new Script( this.context, argument as MirScript, diff --git a/src/utils.ts b/src/utils.ts index 0ca16efd7..c50dcbf1d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -83,13 +83,13 @@ export function getMarkupInputTypeFromArgumentType(argumentType: MirArgumentType } export function getArgumentInfoType(info: ArgumentInfo): MarkupArgumentType { - if (info.type === MirArgumentType.FilterFunction) { + if (info?.type === MirArgumentType.FilterFunction) { return MarkupArgumentType.SelectFilter - } else if (info.type === MirArgumentType.ReducerFunction) { + } else if (info?.type === MirArgumentType.ReducerFunction) { return MarkupArgumentType.SelectReduce - } else if (info.type === MirArgumentType.Subscript) { + } else if (info?.type === MirArgumentType.Subscript) { return MarkupArgumentType.Subscript - } else if (info.type === MirArgumentType.Boolean) { + } else if (info?.type === MirArgumentType.Boolean) { return MarkupArgumentType.SelectBoolean } else { return MarkupArgumentType.Input