diff --git a/hogvm/__tests__/__snapshots__/stl.hoge b/hogvm/__tests__/__snapshots__/stl.hoge index b55b0303ac63a..d9e6ec9c41f51 100644 --- a/hogvm/__tests__/__snapshots__/stl.hoge +++ b/hogvm/__tests__/__snapshots__/stl.hoge @@ -22,4 +22,5 @@ "print", 1, 35, 33, 0, 2, "tuple", 1, 2, "notEmpty", 1, 2, "print", 1, 35, 33, 2, 33, 1, 2, "tuple", 2, 2, "notEmpty", 1, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32, "-- replaceAll, replaceOne --", 2, "print", 1, 35, 32, "L", 32, "l", 32, "hello world", 2, "replaceAll", 3, 2, "print", 1, 35, 32, "L", 32, "l", 32, "hello world", 2, "replaceOne", 3, -2, "print", 1, 35] +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 5d85f96594bf7..d8c2ecb8d346a 100644 --- a/hogvm/__tests__/__snapshots__/stl.stdout +++ b/hogvm/__tests__/__snapshots__/stl.stdout @@ -50,3 +50,6 @@ true -- replaceAll, replaceOne -- heLLo worLd heLlo world + +-- generateUUIDv4 -- +36 diff --git a/hogvm/__tests__/stl.hog b/hogvm/__tests__/stl.hog index 7cb6c0fdba908..3fb041c261677 100644 --- a/hogvm/__tests__/stl.hog +++ b/hogvm/__tests__/stl.hog @@ -50,4 +50,7 @@ print('') print('-- replaceAll, replaceOne --') print(replaceAll('hello world', 'l', 'L')) print(replaceOne('hello world', 'l', 'L')) +print('') +print('-- generateUUIDv4 --') +print(length(generateUUIDv4())) diff --git a/hogvm/python/stl/__init__.py b/hogvm/python/stl/__init__.py index f61674dd3ed1a..33269285b1636 100644 --- a/hogvm/python/stl/__init__.py +++ b/hogvm/python/stl/__init__.py @@ -147,6 +147,14 @@ def replaceAll(name: str, args: list[Any], team: Optional["Team"], stdout: Optio return args[0].replace(args[1], args[2]) +def generateUUIDv4( + name: str, args: list[Any], team: Optional["Team"], stdout: Optional[list[str]], timeout: int +) -> str: + import uuid + + return str(uuid.uuid4()) + + STL: dict[str, Callable[[str, list[Any], Optional["Team"], list[str] | None, int], Any]] = { "concat": concat, "match": match, @@ -173,4 +181,5 @@ def replaceAll(name: str, args: list[Any], team: Optional["Team"], stdout: Optio "decodeURLComponent": decodeURLComponent, "replaceOne": replaceOne, "replaceAll": replaceAll, + "generateUUIDv4": generateUUIDv4, } diff --git a/hogvm/typescript/package.json b/hogvm/typescript/package.json index 53c5805ebe241..9232321bd00ac 100644 --- a/hogvm/typescript/package.json +++ b/hogvm/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@posthog/hogvm", - "version": "1.0.13", + "version": "1.0.14", "description": "PostHog Hog Virtual Machine", "types": "dist/index.d.ts", "main": "dist/index.js", diff --git a/hogvm/typescript/src/stl/stl.ts b/hogvm/typescript/src/stl/stl.ts index 7966e58ff2d93..0e17553f72236 100644 --- a/hogvm/typescript/src/stl/stl.ts +++ b/hogvm/typescript/src/stl/stl.ts @@ -127,6 +127,13 @@ export const STL: Record replaceAll(args) { return args[0].replaceAll(args[1], args[2]) }, + generateUUIDv4() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + const r = (Math.random() * 16) | 0 + const v = c === 'x' ? r : (r & 0x3) | 0x8 + return v.toString(16) + }) + }, } export const ASYNC_STL: Record Promise> = {