-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to flatten webhooks
- Loading branch information
1 parent
48a6e35
commit 3ba964a
Showing
7 changed files
with
60 additions
and
9 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export function flatten(data: any): Record<string, any> { | ||
const result: Record<string, any> = {} | ||
|
||
function recurse(cur: any, prop: string) { | ||
if (Object(cur) !== cur) { | ||
result[prop] = cur | ||
} else if (Array.isArray(cur)) { | ||
for (let i = 0; i < cur.length; i++) { | ||
recurse(cur[i], prop + '_' + i) | ||
} | ||
if (cur.length === 0) { | ||
result[prop] = [] | ||
} | ||
} else { | ||
let isEmpty = true | ||
for (const p in cur) { | ||
isEmpty = false | ||
recurse(cur[p], prop ? prop + '_' + p : p) | ||
} | ||
if (isEmpty && prop) { | ||
result[prop] = {} | ||
} | ||
} | ||
} | ||
|
||
recurse(data, '') | ||
return result | ||
} |
2 changes: 2 additions & 0 deletions
2
apps/trench/src/resources/migrations/v005_webhooks_flatten.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE webhooks | ||
ADD COLUMN IF NOT EXISTS flatten Boolean DEFAULT false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.