@bernierllc/content-type-audio 1.2.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AudioContentTypeManager.js +1 -0
- package/dist/AudioContentTypeManager.js.map +1 -1
- package/dist/errors.d.ts +12 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +25 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
- package/.eslintrc.js +0 -42
- package/CHANGELOG.md +0 -72
- package/__tests__/AudioContentTypeManager.test.ts +0 -592
- package/__tests__/integration.test.ts +0 -279
- package/__tests__/utils.test.ts +0 -142
- package/jest.config.cjs +0 -32
- package/src/AudioContentTypeManager.ts +0 -238
- package/src/index.ts +0 -31
- package/src/schemas.ts +0 -42
- package/src/types.ts +0 -82
- package/src/utils.ts +0 -80
- package/tsconfig.json +0 -19
package/src/index.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2025 Bernier LLC
|
|
3
|
-
|
|
4
|
-
This file is licensed to the client under a limited-use license.
|
|
5
|
-
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
-
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Export types
|
|
10
|
-
export {
|
|
11
|
-
AudioFormat,
|
|
12
|
-
type AudioMetadata,
|
|
13
|
-
type AudioContentTypeConfig,
|
|
14
|
-
type AudioContentType,
|
|
15
|
-
type AudioValidationResult,
|
|
16
|
-
type PackageResult
|
|
17
|
-
} from './types';
|
|
18
|
-
|
|
19
|
-
// Export schemas
|
|
20
|
-
export { AudioContentSchema, type AudioContent } from './schemas';
|
|
21
|
-
|
|
22
|
-
// Export utilities
|
|
23
|
-
export {
|
|
24
|
-
parseDuration,
|
|
25
|
-
formatDuration,
|
|
26
|
-
calculateBitrate,
|
|
27
|
-
generateAudioId
|
|
28
|
-
} from './utils';
|
|
29
|
-
|
|
30
|
-
// Export manager
|
|
31
|
-
export { AudioContentTypeManager, validateAudio } from './AudioContentTypeManager';
|
package/src/schemas.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2025 Bernier LLC
|
|
3
|
-
|
|
4
|
-
This file is licensed to the client under a limited-use license.
|
|
5
|
-
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
-
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { z } from 'zod';
|
|
10
|
-
import { AudioFormat } from './types';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Zod schema for audio content type validation
|
|
14
|
-
*/
|
|
15
|
-
export const AudioContentSchema = z.object({
|
|
16
|
-
id: z.string(),
|
|
17
|
-
type: z.literal('audio'),
|
|
18
|
-
metadata: z.object({
|
|
19
|
-
filename: z.string(),
|
|
20
|
-
mimeType: z.nativeEnum(AudioFormat),
|
|
21
|
-
size: z.number().positive(),
|
|
22
|
-
duration: z.number().nonnegative(),
|
|
23
|
-
bitrate: z.number().positive(),
|
|
24
|
-
sampleRate: z.number().positive().optional(),
|
|
25
|
-
channels: z.number().int().min(1).max(8).optional(),
|
|
26
|
-
title: z.string().optional(),
|
|
27
|
-
artist: z.string().optional(),
|
|
28
|
-
album: z.string().optional(),
|
|
29
|
-
year: z.number().int().min(1900).max(2100).optional(),
|
|
30
|
-
coverArt: z.string().optional()
|
|
31
|
-
}),
|
|
32
|
-
filePath: z.string().optional(),
|
|
33
|
-
fileUrl: z.string().url().optional(),
|
|
34
|
-
streamingUrl: z.string().url().optional(),
|
|
35
|
-
createdAt: z.date(),
|
|
36
|
-
updatedAt: z.date()
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Type inferred from schema
|
|
41
|
-
*/
|
|
42
|
-
export type AudioContent = z.infer<typeof AudioContentSchema>;
|
package/src/types.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2025 Bernier LLC
|
|
3
|
-
|
|
4
|
-
This file is licensed to the client under a limited-use license.
|
|
5
|
-
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
-
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Audio format enumeration
|
|
11
|
-
*/
|
|
12
|
-
export enum AudioFormat {
|
|
13
|
-
MP3 = 'audio/mpeg',
|
|
14
|
-
WAV = 'audio/wav',
|
|
15
|
-
AAC = 'audio/aac',
|
|
16
|
-
OGG = 'audio/ogg',
|
|
17
|
-
FLAC = 'audio/flac',
|
|
18
|
-
M4A = 'audio/mp4'
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Audio metadata interface
|
|
23
|
-
*/
|
|
24
|
-
export interface AudioMetadata {
|
|
25
|
-
filename: string;
|
|
26
|
-
mimeType: AudioFormat;
|
|
27
|
-
size: number; // bytes
|
|
28
|
-
duration: number; // seconds
|
|
29
|
-
bitrate: number; // kbps
|
|
30
|
-
sampleRate?: number; // Hz
|
|
31
|
-
channels?: number; // 1 = mono, 2 = stereo
|
|
32
|
-
title?: string;
|
|
33
|
-
artist?: string;
|
|
34
|
-
album?: string;
|
|
35
|
-
year?: number;
|
|
36
|
-
coverArt?: string; // URL or base64
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Audio content type configuration
|
|
41
|
-
*/
|
|
42
|
-
export interface AudioContentTypeConfig {
|
|
43
|
-
baseType: 'audio';
|
|
44
|
-
editor: 'file-upload-with-player';
|
|
45
|
-
storage: 'file' | 'cloud' | 'custom';
|
|
46
|
-
publishing: 'streaming-url' | 'download' | 'custom';
|
|
47
|
-
maxFileSize?: number; // bytes, default: 100MB
|
|
48
|
-
allowedFormats?: AudioFormat[]; // default: all formats
|
|
49
|
-
requireMetadata?: boolean; // default: false
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Audio content type interface
|
|
54
|
-
*/
|
|
55
|
-
export interface AudioContentType {
|
|
56
|
-
id: string;
|
|
57
|
-
type: 'audio';
|
|
58
|
-
metadata: AudioMetadata;
|
|
59
|
-
filePath?: string; // for local storage
|
|
60
|
-
fileUrl?: string; // for cloud storage
|
|
61
|
-
streamingUrl?: string; // for publishing
|
|
62
|
-
createdAt: Date;
|
|
63
|
-
updatedAt: Date;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Audio validation result
|
|
68
|
-
*/
|
|
69
|
-
export interface AudioValidationResult {
|
|
70
|
-
valid: boolean;
|
|
71
|
-
errors?: string[];
|
|
72
|
-
metadata?: Partial<AudioMetadata>;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Package result interface for error handling
|
|
77
|
-
*/
|
|
78
|
-
export interface PackageResult<T = unknown> {
|
|
79
|
-
success: boolean;
|
|
80
|
-
data?: T;
|
|
81
|
-
error?: string;
|
|
82
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2025 Bernier LLC
|
|
3
|
-
|
|
4
|
-
This file is licensed to the client under a limited-use license.
|
|
5
|
-
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
-
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Parse audio duration from various formats
|
|
11
|
-
* @param duration - Duration as string ("1:23:45", "23:45", "123") or number
|
|
12
|
-
* @returns Duration in seconds
|
|
13
|
-
*/
|
|
14
|
-
export function parseDuration(duration: string | number): number {
|
|
15
|
-
if (typeof duration === 'number') {
|
|
16
|
-
return duration;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Parse formats: "1:23:45", "23:45", "123"
|
|
20
|
-
const parts = duration.split(':').map(Number);
|
|
21
|
-
|
|
22
|
-
// Check if all parts are valid numbers
|
|
23
|
-
if (parts.some(part => isNaN(part))) {
|
|
24
|
-
return 0;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (parts.length === 1) {
|
|
28
|
-
const part = parts[0];
|
|
29
|
-
return part !== undefined ? part : 0; // seconds
|
|
30
|
-
} else if (parts.length === 2) {
|
|
31
|
-
const part0 = parts[0];
|
|
32
|
-
const part1 = parts[1];
|
|
33
|
-
return (part0 !== undefined && part1 !== undefined) ? part0 * 60 + part1 : 0; // mm:ss
|
|
34
|
-
} else if (parts.length === 3) {
|
|
35
|
-
const part0 = parts[0];
|
|
36
|
-
const part1 = parts[1];
|
|
37
|
-
const part2 = parts[2];
|
|
38
|
-
return (part0 !== undefined && part1 !== undefined && part2 !== undefined)
|
|
39
|
-
? part0 * 3600 + part1 * 60 + part2
|
|
40
|
-
: 0; // hh:mm:ss
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Format duration to human-readable string
|
|
48
|
-
* @param seconds - Duration in seconds
|
|
49
|
-
* @returns Formatted string (e.g., "1:23:45" or "23:45")
|
|
50
|
-
*/
|
|
51
|
-
export function formatDuration(seconds: number): string {
|
|
52
|
-
const hours = Math.floor(seconds / 3600);
|
|
53
|
-
const minutes = Math.floor((seconds % 3600) / 60);
|
|
54
|
-
const secs = Math.floor(seconds % 60);
|
|
55
|
-
|
|
56
|
-
if (hours > 0) {
|
|
57
|
-
return `${hours}:${String(minutes).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
|
|
58
|
-
}
|
|
59
|
-
return `${minutes}:${String(secs).padStart(2, '0')}`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Calculate bitrate from file size and duration
|
|
64
|
-
* @param fileSize - File size in bytes
|
|
65
|
-
* @param duration - Duration in seconds
|
|
66
|
-
* @returns Bitrate in kbps
|
|
67
|
-
*/
|
|
68
|
-
export function calculateBitrate(fileSize: number, duration: number): number {
|
|
69
|
-
if (duration === 0) return 0;
|
|
70
|
-
// (fileSize in bytes * 8 bits/byte) / (duration in seconds) / 1000 = kbps
|
|
71
|
-
return Math.round((fileSize * 8) / duration / 1000);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Generate unique ID for audio content
|
|
76
|
-
* @returns Unique identifier
|
|
77
|
-
*/
|
|
78
|
-
export function generateAudioId(): string {
|
|
79
|
-
return `audio_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
80
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist",
|
|
5
|
-
"rootDir": "./src",
|
|
6
|
-
"noEmit": false,
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"sourceMap": true
|
|
10
|
-
},
|
|
11
|
-
"include": [
|
|
12
|
-
"src/**/*"
|
|
13
|
-
],
|
|
14
|
-
"exclude": [
|
|
15
|
-
"node_modules",
|
|
16
|
-
"dist",
|
|
17
|
-
"**/*.test.ts"
|
|
18
|
-
]
|
|
19
|
-
}
|