Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add dev server for in browser development #49

Merged
merged 5 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
end_of_line = lf
charset = utf-8
indent_style = tab
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Add the ability to pass a base URL to all CMCD encode utilities to construct relative paths for `nor` [#50](https://github.com/streaming-video-technology-alliance/common-media-library/issues/50)


## [0.5.1] - 2023-11-16

Expand Down Expand Up @@ -154,7 +157,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.4.3]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.2...v0.4.3
[0.4.2]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.1...v0.4.2
[0.4.1]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.4.0...v0.4.1
[0.4.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.3.0...v0.4.0
[0.4.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.3.0...v0.4.0
[0.3.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.6...v0.3.0
[0.2.6]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.5...v0.2.6
[0.2.5]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.4...v0.2.5
Expand Down
3 changes: 3 additions & 0 deletions dev/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { appendCmcdQuery } from '@svta/common-media-library/cmcd/appendCmcdQuery.js';

console.log(appendCmcdQuery('https://test.com/?CMCD=bs%2Cot%3Dm%2Csf%3Dh', { mtp: 123 }));
8 changes: 8 additions & 0 deletions dev/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>

<body>
<script type="module" src="dev.js"></script>
</body>

</html>
22 changes: 22 additions & 0 deletions dev/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@svta/common-media-library-dev",
"private": true,
"version": "0.5.1",
"license": "Apache-2.0",
"type": "module",
"homepage": "https://github.com/streaming-video-technology-alliance/common-media-library",
"authors": "Casey Occhialini <[email protected]>",
"repository": {
"type": "git",
"url": "git+https://github.com/streaming-video-technology-alliance/common-media-library.git"
},
"bugs": {
"url": "https://github.com/streaming-video-technology-alliance/common-media-library/issues"
},
"scripts": {
"start": "web-dev-server --node-resolve --open --watch"
},
"devDependencies": {
"typedoc": "0.25.2"
}
}
10 changes: 7 additions & 3 deletions lib/config/common-media-library.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ export type CmcdCustomKey = CmCustomKey;

// @beta
export interface CmcdEncodeOptions {
baseUrl?: string;
customHeaderMap?: CmcdHeadersMap;
filter?: (key: CmcdKey) => boolean;
formatters?: Record<CmcdKey, (value: CmcdValue) => number | string>;
formatters?: Record<CmcdKey, CmcdFormatter>;
}

// @beta
Expand All @@ -63,10 +64,10 @@ export enum CmcdEncoding {
}

// @beta
export type CmcdFormatter = (value: CmcdValue) => string;
export type CmcdFormatter = (value: CmcdValue, options?: CmcdEncodeOptions) => string | number;

// @beta
export const CmcdFormatters: Record<string, (value: CmcdValue) => number | string | boolean>;
export const CmcdFormatters: Record<string, CmcdFormatter>;

// @beta
export enum CmcdHeaderField {
Expand Down Expand Up @@ -350,6 +351,9 @@ export function toCmcdJson(cmcd: Cmcd, options?: CmcdEncodeOptions): string;
// @beta
export function toCmcdQuery(cmcd: Cmcd, options?: CmcdEncodeOptions): string;

// @beta
export function urlToRelativePath(url: string, base: string): string;

// @beta
export function utf8ArrayToStr(array: Uint8Array, exitOnNull?: boolean): string;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/cmcd.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* A collection of tools for working with Common Media Client Data (CMCD).
*
*
* @packageDocumentation
*/
export { CMCD_PARAM } from './cmcd/CMCD_PARAM.js';
Expand Down
4 changes: 2 additions & 2 deletions lib/src/cmcd/CMCD_PARAM.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* CMCD parameter name.
*
*
* @group CMCD
*
*
* @beta
*/
export const CMCD_PARAM = 'CMCD';
6 changes: 3 additions & 3 deletions lib/src/cmcd/Cmcd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { CmcdValue } from './CmcdValue.js';

/**
* Common Media Client Data (CMCD) is a standardized set of HTTP request header fields and query string parameters.
*
*
* @see {@link https://cdn.cta.tech/cta/media/media/resources/standards/pdfs/cta-5004-final.pdf|CMCD Spec}
*
*
* @group CMCD
*
*
* @beta
*/
export interface Cmcd {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/cmcd/CmcdCustomKey.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { CmCustomKey } from '../cta/CmCustomKey.js';

/**
* A custom key for CMCD. Custom keys MUST carry a hyphenated prefix
* to ensure that there will not be a namespace collision with future
* revisions to this specification. Clients SHOULD use a reverse-DNS
* A custom key for CMCD. Custom keys MUST carry a hyphenated prefix
* to ensure that there will not be a namespace collision with future
* revisions to this specification. Clients SHOULD use a reverse-DNS
* syntax when defining their own prefix.
*
*
* @group CMCD
*
*
* @beta
*/
export type CmcdCustomKey = CmCustomKey;
43 changes: 24 additions & 19 deletions lib/src/cmcd/CmcdEncodeOptions.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import { CmcdFormatter } from './CmcdFormatter.js';
import { CmcdHeadersMap } from './CmcdHeadersMap.js';
import { CmcdKey } from './CmcdKey.js';
import { CmcdValue } from './CmcdValue.js';

/**
* Options for encoding CMCD values.
*
*
* @group CMCD
*
*
* @beta
*/
export interface CmcdEncodeOptions {
/**
* A map of CMCD keys to custom formatters.
*/
formatters?: Record<CmcdKey, (value: CmcdValue) => number | string>;
/**
* A map of CMCD keys to custom formatters.
*/
formatters?: Record<CmcdKey, CmcdFormatter>;

/**
* A map of CMCD header fields to custom CMCD keys.
*/
customHeaderMap?: CmcdHeadersMap;
/**
* A map of CMCD header fields to custom CMCD keys.
*/
customHeaderMap?: CmcdHeadersMap;

/**
* A filter function for CMCD keys.
*
* @param key - The CMCD key to filter.
*
* @returns `true` if the key should be included, `false` otherwise.
*/
filter?: (key: CmcdKey) => boolean;
/**
* A filter function for CMCD keys.
*
* @param key - The CMCD key to filter.
*
* @returns `true` if the key should be included, `false` otherwise.
*/
filter?: (key: CmcdKey) => boolean;

/**
* The base URL to use for relative URLs.
*/
baseUrl?: string;
}
28 changes: 14 additions & 14 deletions lib/src/cmcd/CmcdEncoding.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/**
* CMCD encoding types.
*
*
* @group CMCD
*
*
* @beta
*/
export enum CmcdEncoding {
/**
* JSON
*/
JSON = 'json',
/**
* JSON
*/
JSON = 'json',

/**
* Query string
*/
QUERY = 'query',
/**
* Query string
*/
QUERY = 'query',

/**
* Request headers
*/
HEADERS = 'headers',
/**
* Request headers
*/
HEADERS = 'headers',
}
11 changes: 6 additions & 5 deletions lib/src/cmcd/CmcdFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { CmcdEncodeOptions } from './CmcdEncodeOptions.js';
import { CmcdValue } from './CmcdValue.js';

/**
* A formatter for CMCD values.
*
*
* @param value - The value to format.
*
*
* @returns The formatted value.
*
*
* @group CMCD
*
*
* @beta
*/
export type CmcdFormatter = (value: CmcdValue) => string;
export type CmcdFormatter = (value: CmcdValue, options?: CmcdEncodeOptions) => string | number;
16 changes: 12 additions & 4 deletions lib/src/cmcd/CmcdFormatters.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { urlToRelativePath } from '../utils.js';
import { CmcdEncodeOptions } from './CmcdEncodeOptions.js';
import { CmcdFormatter } from './CmcdFormatter.js';
import { CmcdValue } from './CmcdValue.js';

const toRounded = (value: CmcdValue) => Math.round(value as number);
const toUrlSafe = (value: CmcdValue) => encodeURIComponent(value as string);
const toUrlSafe = (value: CmcdValue, options?: CmcdEncodeOptions) => {
if (options?.baseUrl) {
value = urlToRelativePath(value as string, options.baseUrl);
}
return encodeURIComponent(value as string);
};
const toHundred = (value: CmcdValue) => toRounded(value as number / 100) * 100;

/**
* The default formatters for CMCD values.
*
*
* @group CMCD
*
*
* @beta
*/
export const CmcdFormatters: Record<string, (value: CmcdValue) => number | string | boolean> = {
export const CmcdFormatters: Record<string, CmcdFormatter> = {
/**
* Bitrate (kbps) rounded integer
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/src/cmcd/CmcdHeaderField.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* CMCD header fields.
*
*
* @group CMCD
*
*
* @beta
*/
export enum CmcdHeaderField {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/cmcd/CmcdHeaderMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { CmcdHeadersMap } from './CmcdHeadersMap.js';

/**
* The map of CMCD header fields to official CMCD keys.
*
*
* @internal
*
*
* @group CMCD
*/
export const CmcdHeaderMap: CmcdHeadersMap = {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/cmcd/CmcdHeadersMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { CmcdKey } from './CmcdKey.js';

/**
* A map of CMCD header fields to CMCD keys.
*
*
* @group CMCD
*
*
* @beta
*/
export type CmcdHeadersMap = Record<CmcdHeaderField, CmcdKey[]>;
4 changes: 2 additions & 2 deletions lib/src/cmcd/CmcdKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Cmcd } from './Cmcd.js';

/**
* A CMCD key.
*
*
* @group CMCD
*
*
* @beta
*/
export type CmcdKey = keyof Cmcd;
4 changes: 2 additions & 2 deletions lib/src/cmcd/CmcdObjectType.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Common Media Object Type
*
*
* @group CMCD
*
*
* @beta
*/
export { CmObjectType as CmcdObjectType } from '../cta/CmObjectType.js';
4 changes: 2 additions & 2 deletions lib/src/cmcd/CmcdStreamType.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Common Media Streaming Type
*
*
* @group CMCD
*
*
* @beta
*/
export { CmStreamType as CmcdStreamType } from '../cta/CmStreamType.js';
4 changes: 2 additions & 2 deletions lib/src/cmcd/CmcdStreamingFormat.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Common Media Streaming Format
*
*
* @group CMCD
*
*
* @beta
*/
export { CmStreamingFormat as CmcdStreamingFormat } from '../cta/CmStreamingFormat.js';
2 changes: 1 addition & 1 deletion lib/src/cmcd/CmcdValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CmValue } from '../cta/CmValue.js';
* CMCD Value
*
* @group CMCD
*
*
* @beta
*/
export type CmcdValue = CmValue;
Loading