From 992d34d113cb4eea6cf45cd628c0900a0c7e9d86 Mon Sep 17 00:00:00 2001 From: Pascal Delange Date: Fri, 10 Jan 2025 12:03:26 +0100 Subject: [PATCH] reintegrate changes from case name templating #647 --- .../src/models/astNode/builder-ast-node.ts | 8 +++-- .../src/models/astNode/data-accessor.ts | 10 +++++- .../app-builder/src/models/astNode/strings.ts | 34 +++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/packages/app-builder/src/models/astNode/builder-ast-node.ts b/packages/app-builder/src/models/astNode/builder-ast-node.ts index 58f747a7..66a5cf1e 100644 --- a/packages/app-builder/src/models/astNode/builder-ast-node.ts +++ b/packages/app-builder/src/models/astNode/builder-ast-node.ts @@ -25,6 +25,8 @@ import { isIsMultipleOf, type IsMultipleOfAstNode } from './multiple-of'; import { type FuzzyMatchComparatorAstNode, isFuzzyMatchComparator, + isStringTemplateAstNode, + type StringTemplateAstNode, } from './strings'; import { isTimeAdd, @@ -38,7 +40,8 @@ export type EditableAstNode = | AggregationAstNode | TimeAddAstNode | FuzzyMatchComparatorAstNode - | IsMultipleOfAstNode; + | IsMultipleOfAstNode + | StringTemplateAstNode; /** * Check if the node is editable in a dedicated modal @@ -51,7 +54,8 @@ export function isEditableAstNode(node: AstNode): node is EditableAstNode { isTimeAdd(node) || isFuzzyMatchComparator(node) || isTimestampExtract(node) || - isIsMultipleOf(node) + isIsMultipleOf(node) || + isStringTemplateAstNode(node) ); } diff --git a/packages/app-builder/src/models/astNode/data-accessor.ts b/packages/app-builder/src/models/astNode/data-accessor.ts index e4f91892..801758e2 100644 --- a/packages/app-builder/src/models/astNode/data-accessor.ts +++ b/packages/app-builder/src/models/astNode/data-accessor.ts @@ -1,5 +1,5 @@ import { type AstNode } from './ast-node'; -import { type ConstantAstNode } from './constant'; +import { type ConstantAstNode, NewConstantAstNode } from './constant'; export const databaseAccessAstNodeName = 'DatabaseAccess'; export interface DatabaseAccessAstNode { @@ -25,6 +25,14 @@ export interface PayloadAstNode { namedChildren: Record; } +export function NewPayloadAstNode(field: string): PayloadAstNode { + return { + name: payloadAstNodeName, + children: [NewConstantAstNode({ constant: field })], + namedChildren: {}, + }; +} + export function isPayload(node: AstNode): node is PayloadAstNode { return node.name === payloadAstNodeName; } diff --git a/packages/app-builder/src/models/astNode/strings.ts b/packages/app-builder/src/models/astNode/strings.ts index 0b734f5d..d288de54 100644 --- a/packages/app-builder/src/models/astNode/strings.ts +++ b/packages/app-builder/src/models/astNode/strings.ts @@ -6,6 +6,10 @@ import { import { type AstNode, NewUndefinedAstNode } from './ast-node'; import { type ConstantAstNode, NewConstantAstNode } from './constant'; +//////////////////////// +// Fuzzy string matching +//////////////////////// + export const fuzzyMatchAstNodeName = 'FuzzyMatch'; export interface FuzzyMatchAstNode { name: typeof fuzzyMatchAstNodeName; @@ -133,3 +137,33 @@ export function isFuzzyMatchComparator( } return isFuzzyMatch(firstChild) || isFuzzyMatchAnyOf(firstChild); } + +//////////////////////// +// String templating /// +//////////////////////// + +export const stringTemplateAstNodeName = 'StringTemplate'; +export interface StringTemplateAstNode { + name: typeof stringTemplateAstNodeName; + constant?: undefined; + children: ConstantAstNode[]; + namedChildren: Record; +} + +export function NewStringTemplateAstNode( + template: string = '', + variables: Record = {}, +): StringTemplateAstNode { + return { + name: stringTemplateAstNodeName, + constant: undefined, + children: [NewConstantAstNode({ constant: template })], + namedChildren: variables, + }; +} + +export function isStringTemplateAstNode( + node: AstNode, +): node is StringTemplateAstNode { + return node.name === stringTemplateAstNodeName; +}