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

feat: add support to additional radon operators #101

Closed
wants to merge 13 commits into from
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
],
"scripts": {
"build": "tsc -p tsconfig.build.json",
"lint": "prettier --write '{src,test}/**/*.{t,j}s'",
"lint:check": "prettier --check '{src,test}/**/*.{t,j}s'",
"lint": "prettier --write {src,test}/**/*.{t,j}s",
"lint:check": "prettier --check {src,test}/**/*.{t,j}s",
"test": "jest",
"prepare": "npm run build"
},
Expand Down
14 changes: 7 additions & 7 deletions src/argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Expand Down
174 changes: 138 additions & 36 deletions src/structures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -35,36 +35,33 @@ export const typeSystem: TypeSystem = {
[ArrayOperatorName.GetString]: [OperatorCode.ArrayGetString, OutputType.String],
[ArrayOperatorName.Map]: [OperatorCode.ArrayMap, OutputType.ArrayMap],
[ArrayOperatorName.Reduce]: [OperatorCode.ArrayReduce, OutputType.Inner],
//[ArrayOperatorName.Some]: [OperatorCode.ArraySome, OutputType.FilterOutput],
[ArrayOperatorName.Sort]: [OperatorCode.ArraySort, OutputType.Same],
//[ArrayOperatorName.Take]: [OperatorCode.ArrayTake, OutputType.Array],
},
[Type.Boolean]: {
[BooleanOperatorName.AsString]: [OperatorCode.BooleanAsString, OutputType.String],
//[BooleanOperatorName.Match]: [OperatorCode.BooleanMatch, OutputType.MatchOutput],
[BooleanOperatorName.ToString]: [OperatorCode.BooleanToString, OutputType.String],
[BooleanOperatorName.Negate]: [OperatorCode.BooleanNegate, OutputType.Boolean],
},
[Type.Bytes]: {
[BytesOperatorName.AsString]: [OperatorCode.BytesAsString, OutputType.String],
[BytesOperatorName.AsInteger]: [OperatorCode.BytesAsInteger, OutputType.Integer],
[BytesOperatorName.Hash]: [OperatorCode.BytesHash, OutputType.Bytes],
[BytesOperatorName.Length]: [OperatorCode.BytesLength, OutputType.Integer],
[BytesOperatorName.Slice]: [OperatorCode.BytesSlice, OutputType.Bytes],
[BytesOperatorName.Stringify]: [OperatorCode.BytesStringify, OutputType.String],
},
[Type.Integer]: {
[IntegerOperatorName.Absolute]: [OperatorCode.IntegerAbsolute, OutputType.Integer],
[IntegerOperatorName.AsFloat]: [OperatorCode.IntegerAsFloat, OutputType.Float],
[IntegerOperatorName.AsString]: [OperatorCode.IntegerAsString, OutputType.String],
[IntegerOperatorName.GreaterThan]: [OperatorCode.IntegerGreaterThan, OutputType.Boolean],
[IntegerOperatorName.LessThan]: [OperatorCode.IntegerLessThan, OutputType.Boolean],
// [IntegerOperatorName.Match]: [OperatorCode.IntegerMatch, OutputType.MatchOutput],
[IntegerOperatorName.Modulo]: [OperatorCode.IntegerModulo, OutputType.Integer],
[IntegerOperatorName.Multiply]: [OperatorCode.IntegerMultiply, OutputType.Integer],
[IntegerOperatorName.Negate]: [OperatorCode.IntegerNegate, OutputType.Integer],
[IntegerOperatorName.Power]: [OperatorCode.IntegerPower, OutputType.Integer],
//[IntegerOperatorName.Reciprocal]: [OperatorCode.IntegerReciprocal, OutputType.Float],
//[IntegerOperatorName.Sum]: [OperatorCode.IntegerSum, OutputType.Integer],
[IntegerOperatorName.ToBytes]: [OperatorCode.IntegerToBytes, OutputType.Bytes],
[IntegerOperatorName.ToFloat]: [OperatorCode.IntegerToFloat, OutputType.Float],
[IntegerOperatorName.ToString]: [OperatorCode.IntegerToString, OutputType.String],
},
[Type.Float]: {
[FloatOperatorName.Absolute]: [OperatorCode.FloatAbsolute, OutputType.Float],
[FloatOperatorName.AsString]: [OperatorCode.FloatAsString, OutputType.String],
[FloatOperatorName.Ceiling]: [OperatorCode.FloatCeiling, OutputType.Integer],
[FloatOperatorName.GreaterThan]: [OperatorCode.FloatGreaterThan, OutputType.Boolean],
[FloatOperatorName.Floor]: [OperatorCode.FloatFloor, OutputType.Integer],
Expand All @@ -73,9 +70,8 @@ export const typeSystem: TypeSystem = {
[FloatOperatorName.Multiply]: [OperatorCode.FloatMultiply, OutputType.Float],
[FloatOperatorName.Negate]: [OperatorCode.FloatNegate, OutputType.Float],
[FloatOperatorName.Power]: [OperatorCode.FloatPower, OutputType.Float],
//[FloatOperatorName.Reciprocal]: [OperatorCode.FloatReciprocal, OutputType.Float],
[FloatOperatorName.Round]: [OperatorCode.FloatRound, OutputType.Integer],
//[FloatOperatorName.Sum]: [OperatorCode.Floatsum, OutputType.Float],
[FloatOperatorName.ToString]: [OperatorCode.FloatToString, OutputType.String],
[FloatOperatorName.Truncate]: [OperatorCode.FloatTruncate, OutputType.Integer],
},
[Type.Map]: {
Expand All @@ -92,7 +88,7 @@ export const typeSystem: TypeSystem = {
},
[Type.String]: {
[StringOperatorName.AsBoolean]: [OperatorCode.StringAsBoolean, OutputType.Boolean],
//[StringOperatorName.AsBytes]: [OperatorCode.StringAsBytes, OutputType.Bytes],
[StringOperatorName.AsBytes]: [OperatorCode.StringAsBytes, OutputType.Bytes],
[StringOperatorName.AsFloat]: [OperatorCode.StringAsFloat, OutputType.Float],
[StringOperatorName.AsInteger]: [OperatorCode.StringAsInteger, OutputType.Integer],
[StringOperatorName.Length]: [OperatorCode.StringLength, OutputType.Integer],
Expand All @@ -102,6 +98,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],
},
}

Expand Down Expand Up @@ -169,20 +168,22 @@ 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,
Expand Down Expand Up @@ -351,9 +352,9 @@ export const operatorInfos: OperatorInfos = {
description: (i18n: I18n) => (min, max) =>
i18n.t('operator_info_description.array.take', { min, max }),
},*/
[OperatorCode.BooleanAsString]: {
[OperatorCode.BooleanToString]: {
type: Type.Boolean,
name: BooleanOperatorName.AsString,
name: BooleanOperatorName.ToString,
arguments: [],
outputType: OutputType.String,
description: (i18n: I18n) => () => descriptions.cast(i18n)('Boolean', 'String'),
Expand Down Expand Up @@ -384,10 +385,16 @@ export const operatorInfos: OperatorInfos = {
outputType: OutputType.Boolean,
description: (i18n: I18n) => () => i18n.t('operator_info_description.boolean.negate'),
},
[OperatorCode.BytesAsString]: {
[OperatorCode.BytesStringify]: {
type: Type.Bytes,
name: BytesOperatorName.AsString,
arguments: [],
name: BytesOperatorName.Stringify,
arguments: [
{
name: 'encoding',
optional: true,
type: MirArgumentType.Integer,
},
],
outputType: OutputType.String,
description: (i18n: I18n) => () => descriptions.cast(i18n)('Bytes', 'String'),
},
Expand All @@ -398,23 +405,54 @@ export const operatorInfos: OperatorInfos = {
outputType: OutputType.Bytes,
description: (i18n: I18n) => () => i18n.t('operator_info_description.bytes.hash'),
},
[OperatorCode.BytesAsInteger]: {
type: Type.Bytes,
name: BytesOperatorName.AsInteger,
arguments: [],
outputType: OutputType.Integer,
description: (i18n: I18n) => () => descriptions.cast(i18n)('Bytes', 'Integer'),
},
[OperatorCode.BytesLength]: {
type: Type.Bytes,
name: BytesOperatorName.Length,
arguments: [],
outputType: OutputType.Integer,
description: (i18n: I18n) => () => i18n.t('operator_info_description.bytes.length'),
},
[OperatorCode.BytesSlice]: {
type: Type.Bytes,
name: BytesOperatorName.Slice,
arguments: [],
outputType: OutputType.Bytes,
description:
(i18n: I18n) =>
(startIndex: number = 0, endIndex: number) =>
i18n.t('operator_info_description.bytes.slice', { startIndex, endIndex }),
},
[OperatorCode.IntegerAbsolute]: {
type: Type.Integer,
name: IntegerOperatorName.Absolute,
arguments: [],
outputType: OutputType.Integer,
description: (i18n: I18n) => () => i18n.t('operator_info_description.integer.absolute'),
},
[OperatorCode.IntegerAsFloat]: {
[OperatorCode.IntegerToBytes]: {
type: Type.Integer,
name: IntegerOperatorName.ToBytes,
arguments: [],
outputType: OutputType.Bytes,
description: (i18n: I18n) => () => descriptions.cast(i18n)('Integer', 'Bytes'),
},
[OperatorCode.IntegerToFloat]: {
type: Type.Integer,
name: IntegerOperatorName.AsFloat,
name: IntegerOperatorName.ToFloat,
arguments: [],
outputType: OutputType.Float,
description: (i18n: I18n) => () => descriptions.cast(i18n)('Integer', 'Float'),
},
[OperatorCode.IntegerAsString]: {
[OperatorCode.IntegerToString]: {
type: Type.Integer,
name: IntegerOperatorName.AsString,
name: IntegerOperatorName.ToString,
arguments: [],
outputType: OutputType.String,
description: (i18n: I18n) => () => descriptions.cast(i18n)('Integer', 'String'),
Expand Down Expand Up @@ -553,9 +591,9 @@ export const operatorInfos: OperatorInfos = {
outputType: OutputType.Float,
description: (i18n: I18n) => () => i18n.t('operator_info_description.float.absolute'),
},
[OperatorCode.FloatAsString]: {
[OperatorCode.FloatToString]: {
type: Type.Float,
name: FloatOperatorName.AsString,
name: FloatOperatorName.ToString,
arguments: [
{
name: 'decimals',
Expand Down Expand Up @@ -863,13 +901,19 @@ export const operatorInfos: OperatorInfos = {
outputType: OutputType.Boolean,
description: (i18n: I18n) => () => descriptions.cast(i18n)('String', 'Boolean'),
},
/*[OperatorCode.StringAsBytes]: {
[OperatorCode.StringAsBytes]: {
type: Type.String,
name: StringOperatorName.AsBytes,
arguments: [],
arguments: [
{
name: 'encoding',
optional: true,
type: MirArgumentType.Integer,
},
],
outputType: OutputType.Bytes,
description: (i18n: I18n) => () => descriptions.cast(i18n)('String', 'Bytes'),
},*/
},
[OperatorCode.StringAsFloat]: {
type: Type.String,
name: StringOperatorName.AsFloat,
Expand Down Expand Up @@ -947,6 +991,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 {
Expand Down
Loading
Loading