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

fix: refactor enums to const #108

Merged
merged 13 commits into from
Oct 29, 2024
3 changes: 3 additions & 0 deletions 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]

### Changed
- Replace Typescript enums with constants [#103](https://github.com/streaming-video-technology-alliance/common-media-library/issues/103)


## [0.7.3] - 2024-08-30

Expand Down
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import js from '@eslint/js';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import tsdoc from 'eslint-plugin-tsdoc';
import typescriptEnum from 'eslint-plugin-typescript-enum';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
Expand All @@ -20,10 +21,12 @@ export default [{
}, ...compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:typescript-enum/recommended',
), {
plugins: {
'@typescript-eslint': typescriptEslint,
tsdoc,
'typescript-enum': typescriptEnum,
},

files: ['**/*.js', '**/*.ts'],
Expand Down
166 changes: 90 additions & 76 deletions lib/config/common-media-library.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,30 @@ export type Cmcd = {
rtp?: number;
};

// @beta
export const CMCD_HEADERS = "headers";

// @beta
export const CMCD_JSON = "json";

// @beta
export const CMCD_OBJECT = "CMCD-Object";

// @beta
export const CMCD_PARAM = "CMCD";

// @beta
export const CMCD_QUERY = "query";

// @beta
export const CMCD_REQUEST = "CMCD-Request";

// @beta
export const CMCD_SESSION = "CMCD-Session";

// @beta
export const CMCD_STATUS = "CMCD-Status";

// @beta
export const CMCD_V1 = 1;

Expand All @@ -118,11 +139,16 @@ export type CmcdEncodeOptions = {
};

// @beta
export enum CmcdEncoding {
HEADERS = "headers",
JSON = "json",
QUERY = "query"
}
export const CmcdEncoding: {
readonly JSON: typeof CMCD_JSON;
readonly QUERY: typeof CMCD_QUERY;
readonly HEADERS: typeof CMCD_HEADERS;
};

// Warning: (ae-forgotten-export) The symbol "ValueOf" needs to be exported by the entry point index.d.ts
//
// @beta (undocumented)
export type CmcdEncoding = ValueOf<typeof CmcdEncoding>;

// @beta
export type CmcdFormatter = (value: CmcdValue, options?: CmcdEncodeOptions) => string | number;
Expand All @@ -131,45 +157,45 @@ export type CmcdFormatter = (value: CmcdValue, options?: CmcdEncodeOptions) => s
export const CmcdFormatters: Record<string, CmcdFormatter>;

// @beta
export enum CmcdHeaderField {
OBJECT = "CMCD-Object",
REQUEST = "CMCD-Request",
SESSION = "CMCD-Session",
STATUS = "CMCD-Status"
}
export const CmcdHeaderField: {
readonly OBJECT: typeof CMCD_OBJECT;
readonly REQUEST: typeof CMCD_REQUEST;
readonly SESSION: typeof CMCD_SESSION;
readonly STATUS: typeof CMCD_STATUS;
};

// @beta (undocumented)
export type CmcdHeaderField = ValueOf<typeof CmcdHeaderField>;

// @beta
export type CmcdHeadersMap = Record<CmcdHeaderField, CmcdKey[]>;

// @beta
export type CmcdKey = keyof Cmcd;

// Warning: (ae-forgotten-export) The symbol "CmObjectType" needs to be exported by the entry point index.d.ts
//
// @beta
export enum CmcdObjectType {
AUDIO = "a",
CAPTION = "c",
INIT = "i",
KEY = "k",
MANIFEST = "m",
MUXED = "av",
OTHER = "o",
TIMED_TEXT = "tt",
VIDEO = "v"
}
export const CmcdObjectType: typeof CmObjectType;

// @beta (undocumented)
export type CmcdObjectType = CmObjectType;

// Warning: (ae-forgotten-export) The symbol "CmStreamingFormat" needs to be exported by the entry point index.d.ts
//
// @beta
export enum CmcdStreamingFormat {
DASH = "d",
HLS = "h",
OTHER = "o",
SMOOTH = "s"
}
export const CmcdStreamingFormat: typeof CmStreamingFormat;

// @beta (undocumented)
export type CmcdStreamingFormat = CmStreamingFormat;

// Warning: (ae-forgotten-export) The symbol "CmStreamType" needs to be exported by the entry point index.d.ts
//
// @beta
export enum CmcdStreamType {
LIVE = "l",
VOD = "v"
}
export const CmcdStreamType: typeof CmStreamType;

// @beta (undocumented)
export type CmcdStreamType = CmStreamType;

// @beta
export type CmcdValue = CmcdObjectType | CmcdStreamingFormat | CmcdStreamType | string | number | boolean | symbol | SfToken;
Expand All @@ -180,10 +206,10 @@ export type CmcdValue = CmcdObjectType | CmcdStreamingFormat | CmcdStreamType |
export type CmCustomKey = `${string}-${string}`;

// @beta
export const CMSD_DYNAMIC: string;
export const CMSD_DYNAMIC = "CMSD-Dynamic";

// @beta
export const CMSD_STATIC: string;
export const CMSD_STATIC = "CMSD-Static";

// @beta
export const CMSD_V1 = 1;
Expand Down Expand Up @@ -213,23 +239,19 @@ export type CmsdEncodeOptions = {
};

// @beta
export enum CmsdHeaderField {
DYNAMIC = "CMSD-Dynamic",
STATIC = "CMSD-Static"
}
export const CmsdHeaderField: {
readonly STATIC: typeof CMSD_STATIC;
readonly DYNAMIC: typeof CMSD_DYNAMIC;
};

// @beta (undocumented)
export type CmsdHeaderField = ValueOf<typeof CmsdHeaderField>;

// @beta
export enum CmsdObjectType {
AUDIO = "a",
CAPTION = "c",
INIT = "i",
KEY = "k",
MANIFEST = "m",
MUXED = "av",
OTHER = "o",
TIMED_TEXT = "tt",
VIDEO = "v"
}
export const CmsdObjectType: typeof CmObjectType;

// @beta (undocumented)
export type CmsdObjectType = CmObjectType;

// @beta
export type CmsdStatic = {
Expand All @@ -249,25 +271,20 @@ export type CmsdStatic = {
};

// @beta
export enum CmsdStreamingFormat {
DASH = "d",
HLS = "h",
OTHER = "o",
SMOOTH = "s"
}
export const CmsdStreamingFormat: typeof CmStreamingFormat;

// @beta (undocumented)
export type CmsdStreamingFormat = CmStreamingFormat;

// @beta
export enum CmsdStreamType {
LIVE = "l",
VOD = "v"
}
export const CmsdStreamType: typeof CmStreamType;

// @beta (undocumented)
export type CmsdStreamType = CmStreamType;

// @beta
export type CmsdValue = CmsdObjectType | CmsdStreamingFormat | CmsdStreamType | string | number | boolean | symbol | SfToken;

// Warning: (ae-forgotten-export) The symbol "CmObjectType" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "CmStreamingFormat" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "CmStreamType" needs to be exported by the entry point index.d.ts
// Warning: (ae-internal-missing-underscore) The name "CmValue" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal
Expand Down Expand Up @@ -766,20 +783,17 @@ export type Validation = {
};

// @beta
export const enum VerboseLevel {
// (undocumented)
DATA = 3,
// (undocumented)
DEBUG = 3,
// (undocumented)
ERROR = 0,
// (undocumented)
INFO = 2,
// (undocumented)
TEXT = 1,
// (undocumented)
WARNING = 2
}
export const VerboseLevel: {
readonly ERROR: 0;
readonly TEXT: 1;
readonly WARNING: 2;
readonly INFO: 2;
readonly DEBUG: 3;
readonly DATA: 3;
};

// @beta (undocumented)
export type VerboseLevel = ValueOf<typeof VerboseLevel>;

// @alpha
export type VideoTrack = Track & {
Expand Down
15 changes: 11 additions & 4 deletions lib/src/cmcd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
*
* @beta
*/
export { appendCmcdHeaders } from './cmcd/appendCmcdHeaders.js';
export { appendCmcdQuery } from './cmcd/appendCmcdQuery.js';
export type { Cmcd } from './cmcd/Cmcd.js';
export { CMCD_HEADERS } from './cmcd/CMCD_HEADERS.js';
export { CMCD_JSON } from './cmcd/CMCD_JSON.js';
export { CMCD_OBJECT } from './cmcd/CMCD_OBJECT.js';
export { CMCD_PARAM } from './cmcd/CMCD_PARAM.js';
export { CMCD_QUERY } from './cmcd/CMCD_QUERY.js';
export { CMCD_REQUEST } from './cmcd/CMCD_REQUEST.js';
export { CMCD_SESSION } from './cmcd/CMCD_SESSION.js';
export { CMCD_STATUS } from './cmcd/CMCD_STATUS.js';
export { CMCD_V1 } from './cmcd/CMCD_V1.js';
export type { Cmcd } from './cmcd/Cmcd.js';
export type { CmcdCustomKey } from './cmcd/CmcdCustomKey.js';
export type { CmcdEncodeOptions } from './cmcd/CmcdEncodeOptions.js';
export { CmcdEncoding } from './cmcd/CmcdEncoding.js';
Expand All @@ -17,11 +26,9 @@ export { CmcdHeaderField } from './cmcd/CmcdHeaderField.js';
export type { CmcdHeadersMap } from './cmcd/CmcdHeadersMap.js';
export type { CmcdKey } from './cmcd/CmcdKey.js';
export { CmcdObjectType } from './cmcd/CmcdObjectType.js';
export { CmcdStreamType } from './cmcd/CmcdStreamType.js';
export { CmcdStreamingFormat } from './cmcd/CmcdStreamingFormat.js';
export { CmcdStreamType } from './cmcd/CmcdStreamType.js';
export type { CmcdValue } from './cmcd/CmcdValue.js';
export { appendCmcdHeaders } from './cmcd/appendCmcdHeaders.js';
export { appendCmcdQuery } from './cmcd/appendCmcdQuery.js';
export { decodeCmcd } from './cmcd/decodeCmcd.js';
export { encodeCmcd } from './cmcd/encodeCmcd.js';
export { fromCmcdHeaders } from './cmcd/fromCmcdHeaders.js';
Expand Down
8 changes: 8 additions & 0 deletions lib/src/cmcd/CMCD_HEADERS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* CMCD `headers` transmission mode.
*
* @group CMCD
*
* @beta
*/
export const CMCD_HEADERS = 'headers';
8 changes: 8 additions & 0 deletions lib/src/cmcd/CMCD_JSON.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* CMCD `json` transmission mode.
*
* @group CMCD
*
* @beta
*/
export const CMCD_JSON = 'json';
8 changes: 8 additions & 0 deletions lib/src/cmcd/CMCD_OBJECT.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* CMCD object header name.
*
* @group CMCD
*
* @beta
*/
export const CMCD_OBJECT = 'CMCD-Object';
8 changes: 8 additions & 0 deletions lib/src/cmcd/CMCD_QUERY.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* CMCD `query` transmission mode.
*
* @group CMCD
*
* @beta
*/
export const CMCD_QUERY = 'query';
8 changes: 8 additions & 0 deletions lib/src/cmcd/CMCD_REQUEST.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* CMCD request header name.
*
* @group CMCD
*
* @beta
*/
export const CMCD_REQUEST = 'CMCD-Request';
8 changes: 8 additions & 0 deletions lib/src/cmcd/CMCD_SESSION.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* CMCD session header name.
*
* @group CMCD
*
* @beta
*/
export const CMCD_SESSION = 'CMCD-Session';
8 changes: 8 additions & 0 deletions lib/src/cmcd/CMCD_STATUS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* CMCD status header name.
*
* @group CMCD
*
* @beta
*/
export const CMCD_STATUS = 'CMCD-Status';
Loading
Loading