-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Simplify Stitcher playlist generation (#114)
* fix: Store vmap text instead of full response object * Simpler playlist generation * Added superjson serialize * Added group logic
- Loading branch information
Showing
10 changed files
with
225 additions
and
186 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export class Group<K = unknown, V = unknown> { | ||
constructor(public map = new Map<K, Set<V>>()) {} | ||
|
||
add(key: K, value: V) { | ||
let set = this.map.get(key); | ||
if (!set) { | ||
set = new Set(); | ||
this.map.set(key, set); | ||
} | ||
set.add(value); | ||
} | ||
|
||
forEach(callback: (value: K, items: V[]) => void) { | ||
Array.from(this.map.entries()).forEach(([key, set]) => { | ||
const items = Array.from(set.values()); | ||
callback(key, items); | ||
}); | ||
} | ||
|
||
get(key: K) { | ||
const set = this.map.get(key); | ||
return set ? Array.from(set.values()) : []; | ||
} | ||
} |
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,31 @@ | ||
import { DateTime } from "luxon"; | ||
import { assert } from "shared/assert"; | ||
import { parse, registerCustom, stringify } from "superjson"; | ||
import { Group } from "./group"; | ||
|
||
registerCustom<DateTime, string>( | ||
{ | ||
isApplicable: (value) => DateTime.isDateTime(value), | ||
serialize: (dateTime) => { | ||
const value = dateTime.toISO(); | ||
assert(value, "No convert to ISO"); | ||
return value; | ||
}, | ||
deserialize: (value) => DateTime.fromISO(value), | ||
}, | ||
"DateTime", | ||
); | ||
|
||
registerCustom<Group, string>( | ||
{ | ||
isApplicable: (value) => value instanceof Group, | ||
serialize: (group) => stringify(group.map), | ||
deserialize: (value) => new Group(parse(value)), | ||
}, | ||
"Group", | ||
); | ||
|
||
export const JSON = { | ||
parse, | ||
stringify, | ||
}; |
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
Oops, something went wrong.