Skip to content

Commit

Permalink
Migrated stitcher to Bun
Browse files Browse the repository at this point in the history
  • Loading branch information
matvp91 committed Oct 10, 2024
1 parent d8a6aa6 commit 1c7c654
Show file tree
Hide file tree
Showing 20 changed files with 1,641 additions and 100 deletions.
175 changes: 175 additions & 0 deletions packages/stitcher/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
15 changes: 15 additions & 0 deletions packages/stitcher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# @mixwave/stitcher

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run index.ts
```

This project was created using `bun init` in bun v1.0.25. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
2 changes: 2 additions & 0 deletions packages/stitcher/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
preload = ["./test/setup.ts"]
15 changes: 6 additions & 9 deletions packages/stitcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@
"name": "@mixwave/stitcher",
"type": "module",
"scripts": {
"build": "tsc",
"dev": "tsc-watch --noClear --onSuccess \"node ./dist/index.js\"",
"test": "vitest run"
"dev": "bun --watch ./src/index.ts",
"test": "bun test"
},
"devDependencies": {
"@types/bun": "latest",
"@types/hh-mm-ss": "^1.2.3",
"@types/lru-cache": "^7.10.10",
"@types/luxon": "^3.4.2",
"@types/node": "^22.1.0",
"@types/uuid": "^10.0.0",
"tsc-watch": "^6.2.0",
"typescript": "^5.5.4",
"vitest": "^2.1.2"
"typescript": "^5.5.4"
},
"dependencies": {
"@fastify/cors": "^9.0.1",
"@fastify/error": "^4.0.0",
"@mixwave/artisan": "workspace:*",
"@mixwave/shared": "workspace:*",
"@ts-rest/core": "^3.49.3",
"@ts-rest/fastify": "^3.49.3",
"@ts-rest/open-api": "^3.49.3",
Expand All @@ -32,7 +30,6 @@
"redis": "^4.7.0",
"uuid": "^10.0.0",
"vast-client": "workspace:*",
"zod": "^3.23.8",
"@mixwave/shared": "workspace:*"
"zod": "^3.23.8"
}
}
6 changes: 3 additions & 3 deletions packages/stitcher/src/filters.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FilterResolutionInvalidError } from "./errors.js";
import type { MasterPlaylist, Variant } from "./parser/index.js";
import type { SessionFilter } from "./session.js";
import { FilterResolutionInvalidError } from "./errors";
import type { MasterPlaylist, Variant } from "./parser";
import type { SessionFilter } from "./session";

const FILTER_VARIANTS_OPERATOR = {
"<": (a: number, b: number) => a < b,
Expand Down
14 changes: 7 additions & 7 deletions packages/stitcher/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Fastify from "fastify";
import cors from "@fastify/cors";
import { env } from "./env.js";
import { contract } from "./contract.js";
import { initServer } from "@ts-rest/fastify";
import { openApiSpec } from "./openapi.js";
import { createSession } from "./session.js";
import { env } from "./env";
import { contract } from "./contract";
import { openApiSpec } from "./openapi";
import { createSession } from "./session";
import { validateFilter } from "./filters";
import { getMasterUrl } from "./url";
import {
formatMasterPlaylist,
formatMediaPlaylist,
formatAssetList,
} from "./playlist.js";
import { validateFilter } from "./filters.js";
import { getMasterUrl } from "./url.js";
} from "./playlist";

async function buildServer() {
const app = Fastify();
Expand Down
12 changes: 6 additions & 6 deletions packages/stitcher/src/interstitials.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { DateTime } from "luxon";
import { env } from "./env.js";
import { getAdMediasFromVast } from "./vast.js";
import { Presentation } from "./presentation.js";
import { VmapResponse } from "./vmap.js";
import type { DateRange } from "./parser/types.js";
import { env } from "./env";
import { getAdMediasFromVast } from "./vast";
import { Presentation } from "./presentation";
import { VmapResponse } from "./vmap";
import type { DateRange } from "./parser";
import type {
Session,
SessionInterstitialType,
SessionInterstitial,
} from "./session.js";
} from "./session";

type InterstitialAsset = {
URI: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/stitcher/src/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generateOpenApi } from "@ts-rest/open-api";
import { contract } from "./contract.js";
import { contract } from "./contract";

export const openApiSpec = generateOpenApi(contract, {
info: {
Expand Down
21 changes: 7 additions & 14 deletions packages/stitcher/src/playlist.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import {
stringifyMasterPlaylist,
stringifyMediaPlaylist,
} from "./parser/index.js";
import { Presentation } from "./presentation.js";
import { filterMaster } from "./filters.js";
import { fetchVmap } from "./vmap.js";
import { DateTime } from "luxon";
import { getSession, updateSession } from "./session.js";
import {
getStaticDateRanges,
getAssets,
getStaticPDT,
} from "./interstitials.js";
import { PlaylistNoVariants } from "./errors.js";
import { stringifyMasterPlaylist, stringifyMediaPlaylist } from "./parser";
import { Presentation } from "./presentation";
import { filterMaster } from "./filters";
import { fetchVmap } from "./vmap";
import { getSession, updateSession } from "./session";
import { getStaticDateRanges, getAssets, getStaticPDT } from "./interstitials";
import { PlaylistNoVariants } from "./errors";

export async function formatMasterPlaylist(sessionId: string) {
const session = await getSession(sessionId);
Expand Down
8 changes: 4 additions & 4 deletions packages/stitcher/src/presentation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { parseMasterPlaylist, parseMediaPlaylist } from "./parser/index.js";
import { assert } from "./assert.js";
import { getMasterUrl, joinPath, getDir } from "./url.js";
import { LRUCache } from "lru-cache";
import type { Segment, MasterPlaylist } from "./parser/index.js";
import { parseMasterPlaylist, parseMediaPlaylist } from "./parser";
import { assert } from "./assert";
import { getMasterUrl, joinPath, getDir } from "./url";
import type { Segment, MasterPlaylist } from "./parser";

export type MediaType = "video" | "audio" | "text";

Expand Down
2 changes: 1 addition & 1 deletion packages/stitcher/src/redis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createClient } from "redis";
import { env } from "./env.js";
import { env } from "./env";

export const client = createClient({
socket: {
Expand Down
6 changes: 3 additions & 3 deletions packages/stitcher/src/session.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { client } from "./redis.js";
import { randomUUID } from "crypto";
import { DateTime } from "luxon";
import { SessionNotFoundError } from "./errors.js";
import type { VmapResponse } from "./vmap.js";
import { client } from "./redis";
import { SessionNotFoundError } from "./errors";
import type { VmapResponse } from "./vmap";

export type Session = {
id: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/stitcher/src/url.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from "path";
import { env } from "./env.js";
import { UriInvalidError } from "./errors.js";
import { env } from "./env";
import { UriInvalidError } from "./errors";

const uuidRegex = /^[a-z,0-9,-]{36,36}$/;

Expand Down
6 changes: 3 additions & 3 deletions packages/stitcher/src/vast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { addTranscodeJob } from "@mixwave/artisan/producer";
import { VASTClient } from "vast-client";
import { DOMParser } from "@xmldom/xmldom";
import * as uuid from "uuid";
import { NAMESPACE_UUID_AD } from "./const.js";
import { getMasterUrl, isUrlAvailable } from "./url.js";
import type { VmapAdBreak } from "./vmap.js";
import { NAMESPACE_UUID_AD } from "./const";
import { getMasterUrl, isUrlAvailable } from "./url";
import type { VastResponse, VastCreativeLinear, VastAd } from "vast-client";
import type { VmapAdBreak } from "./vmap";

export type AdMedia = {
assetId: string;
Expand Down
3 changes: 0 additions & 3 deletions packages/stitcher/test/globalSetup.ts

This file was deleted.

Loading

0 comments on commit 1c7c654

Please sign in to comment.