Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Aug 13, 2024
1 parent 35278f2 commit a4a4e14
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 47 deletions.
2 changes: 1 addition & 1 deletion plugin-server/src/cdp/hog-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class HogExecutor {
let hogLogs = 0
execRes = exec(invocation.vmState ?? hogFunction.bytecode, {
globals,
timeout: DEFAULT_TIMEOUT_MS, // TODO: Swap this to milliseconds when the package is updated
timeout: DEFAULT_TIMEOUT_MS,
maxAsyncSteps: MAX_ASYNC_STEPS, // NOTE: This will likely be configurable in the future
asyncFunctions: {
// We need to pass these in but they don't actually do anything as it is a sync exec
Expand Down
6 changes: 0 additions & 6 deletions plugin-server/src/cdp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ export type HogFunctionInvocationGlobals = {
properties: Record<string, any>
timestamp: string
url: string
elements_chain: string
elements_chain_href: string
elements_chain_texts: string[]
elements_chain_ids: string[]
elements_chain_elements: string[]
}
person?: {
uuid: string
Expand Down Expand Up @@ -113,7 +108,6 @@ export type HogFunctionFilterGlobals = {
elements_chain_texts: string[]
elements_chain_ids: string[]
elements_chain_elements: string[]

properties: Record<string, any>

person?: {
Expand Down
80 changes: 40 additions & 40 deletions plugin-server/src/cdp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,46 +57,6 @@ export function convertToParsedClickhouseEvent(event: RawClickHouseEvent): Parse
}
}

// extract(elements_chain, '(?::|\")href="(.*?)"'),
const hrefRegex = new RE2(/(?::|")href="(.*?)"/)
function getElementsChainHref(elementsChain: string): string {
const hrefMatch = hrefRegex.exec(elementsChain)
return hrefMatch ? hrefMatch[1] : ''
}

// arrayDistinct(extractAll(elements_chain, '(?::|\")text="(.*?)"')),
const textRegex = new RE2(/(?::|")text="(.*?)"/g)
function getElementsChainTexts(elementsChain: string): string[] {
const textMatches = new Set<string>()
let textMatch
while ((textMatch = textRegex.exec(elementsChain)) !== null) {
textMatches.add(textMatch[1])
}
return Array.from(textMatches)
}

// arrayDistinct(extractAll(elements_chain, '(?::|\")id="(.*?)"')),
const idRegex = new RE2(/(?::|")id="(.*?)"/g)
function getElementsChainIds(elementsChain: string): string[] {
const idMatches = new Set<string>()
let idMatch
while ((idMatch = idRegex.exec(elementsChain)) !== null) {
idMatches.add(idMatch[1])
}
return Array.from(idMatches)
}

// arrayDistinct(extractAll(elements_chain, '(?:^|;)(a|button|form|input|select|textarea|label)(?:\\.|$|:)'))
const elementRegex = new RE2(/(?:^|;)(a|button|form|input|select|textarea|label)(?:\.|$|:)/g)
function getElementsChainElements(elementsChain: string): string[] {
const elementMatches = new Set<string>()
let elementMatch
while ((elementMatch = elementRegex.exec(elementsChain)) !== null) {
elementMatches.add(elementMatch[1])
}
return Array.from(elementMatches)
}

// that we can keep to as a contract
export function convertToHogFunctionInvocationGlobals(
event: RawClickHouseEvent,
Expand Down Expand Up @@ -146,6 +106,46 @@ export function convertToHogFunctionInvocationGlobals(
return context
}

// Adapted from Materialized SQL column: extract(elements_chain, '(?::|\")href="(.*?)"'),
const hrefRegex = new RE2(/(?::|")href="(.*?)"/)
function getElementsChainHref(elementsChain: string): string {
const hrefMatch = hrefRegex.exec(elementsChain)
return hrefMatch ? hrefMatch[1] : ''
}

// Adapted from Materialized SQL column: arrayDistinct(extractAll(elements_chain, '(?::|\")text="(.*?)"')),
const textRegex = new RE2(/(?::|")text="(.*?)"/g)
function getElementsChainTexts(elementsChain: string): string[] {
const textMatches = new Set<string>()
let textMatch
while ((textMatch = textRegex.exec(elementsChain)) !== null) {
textMatches.add(textMatch[1])
}
return Array.from(textMatches)
}

// Adapted from Materialized SQL column: arrayDistinct(extractAll(elements_chain, '(?::|\")id="(.*?)"')),
const idRegex = new RE2(/(?::|")id="(.*?)"/g)
function getElementsChainIds(elementsChain: string): string[] {
const idMatches = new Set<string>()
let idMatch
while ((idMatch = idRegex.exec(elementsChain)) !== null) {
idMatches.add(idMatch[1])
}
return Array.from(idMatches)
}

// Adapted from Materialized SQL column: arrayDistinct(extractAll(elements_chain, '(?:^|;)(a|button|form|input|select|textarea|label)(?:\\.|$|:)'))
const elementRegex = new RE2(/(?:^|;)(a|button|form|input|select|textarea|label)(?:\.|$|:)/g)
function getElementsChainElements(elementsChain: string): string[] {
const elementMatches = new Set<string>()
let elementMatch
while ((elementMatch = elementRegex.exec(elementsChain)) !== null) {
elementMatches.add(elementMatch[1])
}
return Array.from(elementMatches)
}

export function convertToHogFunctionFilterGlobal(globals: HogFunctionInvocationGlobals): HogFunctionFilterGlobals {
const groups: Record<string, any> = {}

Expand Down

0 comments on commit a4a4e14

Please sign in to comment.