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/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/structures.ts b/src/structures.ts index 34da13e4a..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], @@ -102,6 +102,9 @@ 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], + [StringOperatorName.Slice]: [OperatorCode.StringSlice, OutputType.String], + [StringOperatorName.Split]: [OperatorCode.StringSplit, OutputType.String], }, } @@ -169,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, @@ -947,6 +950,64 @@ 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 }), + }, + [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 }), + }, + [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 6795fa8f0..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 { @@ -220,13 +221,14 @@ export type KindOptions = Array export enum Kind { HttpGet = 'HTTP-GET', HttpPost = 'HTTP-POST', + HttpHead = 'HTTP-HEAD', RNG = 'RNG', } export enum OperatorCode { ArrayCount = 0x10, ArrayFilter = 0x11, - //ArrayFlatten = 0x12, + ArrayJoin = 0x12, ArrayGetArray = 0x13, ArrayGetBoolean = 0x14, ArrayGetBytes = 0x15, @@ -298,6 +300,9 @@ export enum OperatorCode { StringParseXmlMap = 0x78, StringToLowerCase = 0x79, StringToUpperCase = 0x7a, + StringReplace = 0x7b, + StringSlice = 0x7c, + StringSplit = 0x7d, } export enum MirArgumentType { @@ -416,7 +421,7 @@ export type OperatorInfos = { export enum ArrayOperatorName { Count = 'count', Filter = 'filter', - //Flatten = 'flatten', + Join = 'join', GetArray = 'getArray', GetBoolean = 'getBoolean', GetBytes = 'getBytes', @@ -499,6 +504,9 @@ export enum StringOperatorName { ParseXmlMap = 'parseXMLMap', ToLowerCase = 'toLowerCase', ToUpperCase = 'toUpperCase', + Replace = 'replace', + Slice = 'slice', + Split = 'split', } export type OperatorName = 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