diff --git a/hogvm/__tests__/__snapshots__/stl.hoge b/hogvm/__tests__/__snapshots__/stl.hoge index 3f842a7d4156f..35cad3352f54c 100644 --- a/hogvm/__tests__/__snapshots__/stl.hoge +++ b/hogvm/__tests__/__snapshots__/stl.hoge @@ -14,13 +14,14 @@ "print", 1, 35, 32, "string", 2, "empty", 1, 2, "print", 1, 35, 32, "0", 2, "empty", 1, 2, "print", 1, 35, 43, 0, 2, "empty", 1, 2, "print", 1, 35, 42, 0, 2, "empty", 1, 2, "print", 1, 35, 2, "tuple", 0, 2, "empty", 1, 2, "print", 1, 35, 33, 0, 2, "tuple", 1, 2, "empty", 1, 2, "print", 1, 35, 33, 1, 33, 2, 2, "tuple", 2, 2, "empty", 1, 2, "print", 1, 35, -32, "", 2, "print", 1, 35, 32, "-- notEmpty --", 2, "print", 1, 35, 31, 2, "notEmpty", 1, 2, "print", 1, 35, 33, 0, 2, -"notEmpty", 1, 2, "print", 1, 35, 33, 1, 2, "notEmpty", 1, 2, "print", 1, 35, 33, -1, 2, "notEmpty", 1, 2, "print", 1, -35, 34, 0.0, 2, "notEmpty", 1, 2, "print", 1, 35, 34, 0.01, 2, "notEmpty", 1, 2, "print", 1, 35, 32, "", 2, "notEmpty", -1, 2, "print", 1, 35, 32, "string", 2, "notEmpty", 1, 2, "print", 1, 35, 32, "0", 2, "notEmpty", 1, 2, "print", 1, 35, -43, 0, 2, "notEmpty", 1, 2, "print", 1, 35, 42, 0, 2, "notEmpty", 1, 2, "print", 1, 35, 2, "tuple", 0, 2, "notEmpty", 1, -2, "print", 1, 35, 33, 0, 2, "tuple", 1, 2, "notEmpty", 1, 2, "print", 1, 35, 33, 1, 33, 2, 2, "tuple", 2, 2, -"notEmpty", 1, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32, "-- replaceAll, replaceOne --", 2, "print", 1, 35, 32, -"hello world", 32, "l", 32, "L", 2, "replaceAll", 3, 2, "print", 1, 35, 32, "hello world", 32, "l", 32, "L", 2, -"replaceOne", 3, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32, "-- generateUUIDv4 --", 2, "print", 1, 35, 2, -"generateUUIDv4", 0, 2, "length", 1, 2, "print", 1, 35] +29, 2, "empty", 1, 2, "print", 1, 35, 30, 2, "empty", 1, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32, +"-- notEmpty --", 2, "print", 1, 35, 31, 2, "notEmpty", 1, 2, "print", 1, 35, 33, 0, 2, "notEmpty", 1, 2, "print", 1, +35, 33, 1, 2, "notEmpty", 1, 2, "print", 1, 35, 33, -1, 2, "notEmpty", 1, 2, "print", 1, 35, 34, 0.0, 2, "notEmpty", 1, +2, "print", 1, 35, 34, 0.01, 2, "notEmpty", 1, 2, "print", 1, 35, 32, "", 2, "notEmpty", 1, 2, "print", 1, 35, 32, +"string", 2, "notEmpty", 1, 2, "print", 1, 35, 32, "0", 2, "notEmpty", 1, 2, "print", 1, 35, 43, 0, 2, "notEmpty", 1, 2, +"print", 1, 35, 42, 0, 2, "notEmpty", 1, 2, "print", 1, 35, 2, "tuple", 0, 2, "notEmpty", 1, 2, "print", 1, 35, 33, 0, +2, "tuple", 1, 2, "notEmpty", 1, 2, "print", 1, 35, 33, 1, 33, 2, 2, "tuple", 2, 2, "notEmpty", 1, 2, "print", 1, 35, +29, 2, "notEmpty", 1, 2, "print", 1, 35, 30, 2, "notEmpty", 1, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32, +"-- replaceAll, replaceOne --", 2, "print", 1, 35, 32, "hello world", 32, "l", 32, "L", 2, "replaceAll", 3, 2, "print", +1, 35, 32, "hello world", 32, "l", 32, "L", 2, "replaceOne", 3, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32, +"-- generateUUIDv4 --", 2, "print", 1, 35, 2, "generateUUIDv4", 0, 2, "length", 1, 2, "print", 1, 35] diff --git a/hogvm/__tests__/__snapshots__/stl.stdout b/hogvm/__tests__/__snapshots__/stl.stdout index d8c2ecb8d346a..f80a819686adc 100644 --- a/hogvm/__tests__/__snapshots__/stl.stdout +++ b/hogvm/__tests__/__snapshots__/stl.stdout @@ -17,10 +17,10 @@ tom & jerry -- empty -- true -true false false -true +false +false false true false @@ -30,13 +30,15 @@ true true false false +false +false -- notEmpty -- false -false true true -false +true +true true false true @@ -46,6 +48,8 @@ false false true true +true +true -- replaceAll, replaceOne -- heLLo worLd diff --git a/hogvm/__tests__/stl.hog b/hogvm/__tests__/stl.hog index 3fb041c261677..2343492d90d71 100644 --- a/hogvm/__tests__/stl.hog +++ b/hogvm/__tests__/stl.hog @@ -30,6 +30,8 @@ print(empty({})) print(empty(tuple())) print(empty(tuple(0))) print(empty(tuple(1,2))) +print(empty(true)) +print(empty(false)) print('') print('-- notEmpty --') print(notEmpty(null)) @@ -46,6 +48,8 @@ print(notEmpty({})) print(notEmpty(tuple())) print(notEmpty(tuple(0))) print(notEmpty(tuple(1,2))) +print(notEmpty(true)) +print(notEmpty(false)) print('') print('-- replaceAll, replaceOne --') print(replaceAll('hello world', 'l', 'L')) diff --git a/hogvm/python/stl/__init__.py b/hogvm/python/stl/__init__.py index a20b39d8c00bf..9312d6d5afbb8 100644 --- a/hogvm/python/stl/__init__.py +++ b/hogvm/python/stl/__init__.py @@ -100,6 +100,12 @@ def ifNull(args: list[Any], team: Optional["Team"], stdout: Optional[list[str]], return args[1] +def empty(args: list[Any], team: Optional["Team"], stdout: Optional[list[str]], timeout: float): + if isinstance(args[0], bool) or isinstance(args[0], int) or isinstance(args[0], float): + return False + return not bool(args[0]) + + def sleep(args: list[Any], team: Optional["Team"], stdout: Optional[list[str]], timeout: float): time.sleep(args[0]) return None @@ -367,8 +373,10 @@ def _typeof(args: list[Any], team: Optional["Team"], stdout: Optional[list[str]] "toFloat": STLFunction(fn=toFloat, minArgs=1, maxArgs=1), "ifNull": STLFunction(fn=ifNull, minArgs=2, maxArgs=2), "length": STLFunction(fn=lambda args, team, stdout, timeout: len(args[0]), minArgs=1, maxArgs=1), - "empty": STLFunction(fn=lambda args, team, stdout, timeout: not bool(args[0]), minArgs=1, maxArgs=1), - "notEmpty": STLFunction(fn=lambda args, team, stdout, timeout: bool(args[0]), minArgs=1, maxArgs=1), + "empty": STLFunction(fn=empty, minArgs=1, maxArgs=1), + "notEmpty": STLFunction( + fn=lambda args, team, stdout, timeout: not empty(args, team, stdout, timeout), minArgs=1, maxArgs=1 + ), "tuple": STLFunction(fn=lambda args, team, stdout, timeout: tuple(args), minArgs=0, maxArgs=None), "lower": STLFunction(fn=lambda args, team, stdout, timeout: args[0].lower(), minArgs=1, maxArgs=1), "upper": STLFunction(fn=lambda args, team, stdout, timeout: args[0].upper(), minArgs=1, maxArgs=1), diff --git a/hogvm/typescript/package.json b/hogvm/typescript/package.json index c02fa2faf7f9c..b046816d2aa9e 100644 --- a/hogvm/typescript/package.json +++ b/hogvm/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@posthog/hogvm", - "version": "1.0.46", + "version": "1.0.47", "description": "PostHog Hog Virtual Machine", "types": "dist/index.d.ts", "source": "src/index.ts", diff --git a/hogvm/typescript/src/stl/stl.ts b/hogvm/typescript/src/stl/stl.ts index bb2fcb5280a6b..328621560c702 100644 --- a/hogvm/typescript/src/stl/stl.ts +++ b/hogvm/typescript/src/stl/stl.ts @@ -115,6 +115,8 @@ export const STL: Record = { return args[0].size === 0 } return Object.keys(args[0]).length === 0 + } else if (typeof args[0] === 'number' || typeof args[0] === 'boolean') { + return false } return !args[0] }, diff --git a/package.json b/package.json index f6837fc45cf67..56a02c6bb6967 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "@medv/finder": "^3.1.0", "@microlink/react-json-view": "^1.21.3", "@monaco-editor/react": "4.6.0", - "@posthog/hogvm": "^1.0.46", + "@posthog/hogvm": "^1.0.47", "@posthog/icons": "0.8.1", "@posthog/plugin-scaffold": "^1.4.4", "@react-hook/size": "^2.1.2", diff --git a/plugin-server/package.json b/plugin-server/package.json index b6b9147b14bbf..5189b589fb2c9 100644 --- a/plugin-server/package.json +++ b/plugin-server/package.json @@ -53,7 +53,7 @@ "@maxmind/geoip2-node": "^3.4.0", "@posthog/clickhouse": "^1.7.0", "@posthog/cyclotron": "file:../rust/cyclotron-node", - "@posthog/hogvm": "^1.0.46", + "@posthog/hogvm": "^1.0.47", "@posthog/plugin-scaffold": "1.4.4", "@sentry/node": "^7.49.0", "@sentry/profiling-node": "^0.3.0", diff --git a/plugin-server/pnpm-lock.yaml b/plugin-server/pnpm-lock.yaml index dd40fb3bf24e3..cfa431883a768 100644 --- a/plugin-server/pnpm-lock.yaml +++ b/plugin-server/pnpm-lock.yaml @@ -47,8 +47,8 @@ dependencies: specifier: file:../rust/cyclotron-node version: file:../rust/cyclotron-node '@posthog/hogvm': - specifier: ^1.0.46 - version: 1.0.46(luxon@3.4.4) + specifier: ^1.0.47 + version: 1.0.47(luxon@3.4.4) '@posthog/plugin-scaffold': specifier: 1.4.4 version: 1.4.4 @@ -3116,8 +3116,8 @@ packages: engines: {node: '>=12'} dev: false - /@posthog/hogvm@1.0.46(luxon@3.4.4): - resolution: {integrity: sha512-oTXytxHImxcAUYvK+QVI5nRc3YnVSbn01rFlOrpeTYjW5oqYKMR8nYsjhHGLt5p0pnfeBhmQjBM5mJtVs5bA2Q==} + /@posthog/hogvm@1.0.47(luxon@3.4.4): + resolution: {integrity: sha512-6zoMKH6fmO9evuhpd9dtkVi2GFk+dGsxcHe6l6mMo7yXd0Kwssmiwr8aLndYTsjdhRkVMi7iaoi/GLrh8F9ayQ==} peerDependencies: luxon: ^3.4.4 dependencies: diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 653bfb354e482..4a3666258f3aa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -53,8 +53,8 @@ dependencies: specifier: 4.6.0 version: 4.6.0(monaco-editor@0.49.0)(react-dom@18.2.0)(react@18.2.0) '@posthog/hogvm': - specifier: ^1.0.46 - version: 1.0.46(luxon@3.5.0) + specifier: ^1.0.47 + version: 1.0.47(luxon@3.5.0) '@posthog/icons': specifier: 0.8.1 version: 0.8.1(react-dom@18.2.0)(react@18.2.0) @@ -5414,8 +5414,8 @@ packages: resolution: {integrity: sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==} dev: false - /@posthog/hogvm@1.0.46(luxon@3.5.0): - resolution: {integrity: sha512-oTXytxHImxcAUYvK+QVI5nRc3YnVSbn01rFlOrpeTYjW5oqYKMR8nYsjhHGLt5p0pnfeBhmQjBM5mJtVs5bA2Q==} + /@posthog/hogvm@1.0.47(luxon@3.5.0): + resolution: {integrity: sha512-6zoMKH6fmO9evuhpd9dtkVi2GFk+dGsxcHe6l6mMo7yXd0Kwssmiwr8aLndYTsjdhRkVMi7iaoi/GLrh8F9ayQ==} peerDependencies: luxon: ^3.4.4 dependencies: @@ -18298,7 +18298,7 @@ packages: react: '>=15' dependencies: react: 18.2.0 - unlayer-types: 1.75.0 + unlayer-types: 1.77.0 dev: false /react-error-boundary@3.1.4(react@18.2.0): @@ -20832,8 +20832,8 @@ packages: resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==} engines: {node: '>= 10.0.0'} - /unlayer-types@1.75.0: - resolution: {integrity: sha512-yB4TeimlZPKkAGIIE3Acs9e5YHjCpeGcoybq/E8w4lzNTI5EybI9Z9rwIBXhNK0miNarxEIO7rJUWB+Yeve80g==} + /unlayer-types@1.77.0: + resolution: {integrity: sha512-/eIyHiGWO/EFb3GuD7FqD+jV9sXAj2FMhwn3QTVaio2FUz30RRAh8kQS+qNwPKIcLEZWKzfH41SBi3afudEVAA==} dev: false /unpipe@1.0.0: