forked from andyburke/autonomous.contact
refactor: events to a pure stream instead of being part of topics
NOTE: tests are passing, but the client is broken
This commit is contained in:
parent
c34069066d
commit
a5707e2f81
31 changed files with 934 additions and 686 deletions
30
utils/object_helpers.ts
Normal file
30
utils/object_helpers.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
export function flatten(obj: Record<string, any>, path?: string, result?: Record<string, any>) {
|
||||
result = result ?? {};
|
||||
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (typeof value === 'object') {
|
||||
flatten(value, (path ?? '') + key + '.', result);
|
||||
} else {
|
||||
result[(path ?? '') + key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function expand(obj: Record<string, any>) {
|
||||
const result: Record<string, any> = {};
|
||||
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
const elements = key.split('.');
|
||||
|
||||
let current = result;
|
||||
for (const element of elements.slice(0, elements.length - 1)) {
|
||||
current[element] = current[element] ?? {};
|
||||
current = current[element];
|
||||
}
|
||||
current[elements[elements.length - 1]] = value;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue