taglib-wasm 0.3.13 → 0.3.15

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.
Files changed (82) hide show
  1. package/README.md +22 -35
  2. package/dist/index.d.ts +10 -10
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +117 -134
  5. package/dist/index.js.map +1 -0
  6. package/dist/src/constants.js +211 -0
  7. package/dist/src/constants.js.map +1 -0
  8. package/dist/src/errors.js +180 -0
  9. package/dist/src/errors.js.map +1 -0
  10. package/dist/src/file-utils.d.ts +2 -2
  11. package/dist/src/file-utils.d.ts.map +1 -1
  12. package/dist/src/file-utils.js +394 -0
  13. package/dist/src/file-utils.js.map +1 -0
  14. package/dist/src/mod.d.ts +4 -4
  15. package/dist/src/mod.d.ts.map +1 -1
  16. package/dist/src/mod.js +7 -0
  17. package/dist/src/mod.js.map +1 -0
  18. package/dist/src/simple.d.ts +4 -4
  19. package/dist/src/simple.d.ts.map +1 -1
  20. package/dist/src/{simple.ts → simple.js} +193 -311
  21. package/dist/src/simple.js.map +1 -0
  22. package/dist/src/taglib.d.ts +3 -3
  23. package/dist/src/taglib.d.ts.map +1 -1
  24. package/dist/src/taglib.js +516 -0
  25. package/dist/src/taglib.js.map +1 -0
  26. package/dist/src/types.d.ts +2 -2
  27. package/dist/src/types.d.ts.map +1 -1
  28. package/dist/src/types.js +239 -0
  29. package/dist/src/types.js.map +1 -0
  30. package/dist/src/utils/file.js +65 -0
  31. package/dist/src/utils/file.js.map +1 -0
  32. package/dist/src/utils/write.js +49 -0
  33. package/dist/src/utils/write.js.map +1 -0
  34. package/dist/src/wasm-workers.d.ts +1 -1
  35. package/dist/src/wasm-workers.d.ts.map +1 -1
  36. package/dist/src/wasm-workers.js +148 -0
  37. package/dist/src/wasm-workers.js.map +1 -0
  38. package/dist/src/wasm.js +6 -0
  39. package/dist/src/wasm.js.map +1 -0
  40. package/dist/src/web-utils.d.ts +2 -2
  41. package/dist/src/web-utils.d.ts.map +1 -1
  42. package/{src/web-utils.ts → dist/src/web-utils.js} +102 -184
  43. package/dist/src/web-utils.js.map +1 -0
  44. package/dist/src/workers.d.ts +2 -2
  45. package/dist/src/workers.d.ts.map +1 -1
  46. package/dist/src/workers.js +389 -0
  47. package/dist/src/workers.js.map +1 -0
  48. package/dist/taglib-wrapper.js +8 -2528
  49. package/package.json +7 -10
  50. package/dist/index.ts +0 -221
  51. package/dist/src/constants.ts +0 -227
  52. package/dist/src/errors.ts +0 -254
  53. package/dist/src/file-utils.ts +0 -483
  54. package/dist/src/file.js +0 -52
  55. package/dist/src/global.d.ts +0 -12
  56. package/dist/src/mod.ts +0 -19
  57. package/dist/src/taglib.ts +0 -961
  58. package/dist/src/types.ts +0 -538
  59. package/dist/src/utils/file.ts +0 -86
  60. package/dist/src/utils/write.ts +0 -66
  61. package/dist/src/wasm-workers.ts +0 -176
  62. package/dist/src/wasm.ts +0 -133
  63. package/dist/src/web-utils.ts +0 -347
  64. package/dist/src/workers.ts +0 -461
  65. package/dist/src/write.js +0 -33
  66. package/index.ts +0 -221
  67. package/lib/taglib/COPYING.LGPL +0 -502
  68. package/lib/taglib/COPYING.MPL +0 -470
  69. package/lib/taglib/README.md +0 -24
  70. package/src/constants.ts +0 -227
  71. package/src/errors.ts +0 -254
  72. package/src/file-utils.ts +0 -483
  73. package/src/global.d.ts +0 -12
  74. package/src/mod.ts +0 -19
  75. package/src/simple.ts +0 -667
  76. package/src/taglib.ts +0 -961
  77. package/src/types.ts +0 -538
  78. package/src/utils/file.ts +0 -86
  79. package/src/utils/write.ts +0 -66
  80. package/src/wasm-workers.ts +0 -176
  81. package/src/wasm.ts +0 -133
  82. package/src/workers.ts +0 -461
@@ -1,254 +0,0 @@
1
- /**
2
- * Custom error types for taglib-wasm with enhanced context and debugging information
3
- */
4
-
5
- /**
6
- * List of audio formats supported by taglib-wasm
7
- */
8
- export const SUPPORTED_FORMATS = [
9
- "MP3",
10
- "MP4",
11
- "M4A",
12
- "FLAC",
13
- "OGG",
14
- "WAV",
15
- ] as const;
16
-
17
- /**
18
- * Error codes for programmatic error handling
19
- */
20
- export enum TagLibErrorCode {
21
- INITIALIZATION_FAILED = "INITIALIZATION_FAILED",
22
- INVALID_FORMAT = "INVALID_FORMAT",
23
- UNSUPPORTED_FORMAT = "UNSUPPORTED_FORMAT",
24
- FILE_OPERATION_FAILED = "FILE_OPERATION_FAILED",
25
- METADATA_ERROR = "METADATA_ERROR",
26
- MEMORY_ERROR = "MEMORY_ERROR",
27
- ENVIRONMENT_ERROR = "ENVIRONMENT_ERROR",
28
- }
29
-
30
- /**
31
- * Base error class for all taglib-wasm errors
32
- */
33
- export class TagLibError extends Error {
34
- constructor(
35
- message: string,
36
- public readonly code: TagLibErrorCode,
37
- public readonly context?: Record<string, unknown>,
38
- ) {
39
- super(message);
40
- this.name = "TagLibError";
41
- Object.setPrototypeOf(this, TagLibError.prototype);
42
- }
43
- }
44
-
45
- /**
46
- * Error thrown when the Wasm module fails to initialize
47
- */
48
- export class TagLibInitializationError extends TagLibError {
49
- constructor(message: string, context?: Record<string, unknown>) {
50
- super(
51
- createErrorMessage("Failed to initialize TagLib Wasm module", message),
52
- TagLibErrorCode.INITIALIZATION_FAILED,
53
- context,
54
- );
55
- this.name = "TagLibInitializationError";
56
- Object.setPrototypeOf(this, TagLibInitializationError.prototype);
57
- }
58
- }
59
-
60
- /**
61
- * Error thrown when an audio file format is invalid or corrupted
62
- */
63
- export class InvalidFormatError extends TagLibError {
64
- constructor(
65
- message: string,
66
- public readonly bufferSize?: number,
67
- context?: Record<string, unknown>,
68
- ) {
69
- const details = [`Invalid audio file format: ${message}`];
70
-
71
- if (bufferSize !== undefined) {
72
- details.push(`Buffer size: ${formatFileSize(bufferSize)}`);
73
- if (bufferSize < 1024) {
74
- details.push(
75
- "Audio files must be at least 1KB to contain valid headers.",
76
- );
77
- }
78
- }
79
-
80
- super(
81
- details.join(". "),
82
- TagLibErrorCode.INVALID_FORMAT,
83
- { ...context, bufferSize },
84
- );
85
- this.name = "InvalidFormatError";
86
- Object.setPrototypeOf(this, InvalidFormatError.prototype);
87
- }
88
- }
89
-
90
- /**
91
- * Error thrown when an audio format is recognized but not supported
92
- */
93
- export class UnsupportedFormatError extends TagLibError {
94
- constructor(
95
- public readonly format: string,
96
- public readonly supportedFormats: readonly string[] = SUPPORTED_FORMATS,
97
- context?: Record<string, unknown>,
98
- ) {
99
- super(
100
- `Unsupported audio format: ${format}. Supported formats: ${
101
- supportedFormats.join(", ")
102
- }`,
103
- TagLibErrorCode.UNSUPPORTED_FORMAT,
104
- { ...context, format, supportedFormats },
105
- );
106
- this.name = "UnsupportedFormatError";
107
- Object.setPrototypeOf(this, UnsupportedFormatError.prototype);
108
- }
109
- }
110
-
111
- /**
112
- * Error thrown during file operations (read, write, save)
113
- */
114
- export class FileOperationError extends TagLibError {
115
- constructor(
116
- public readonly operation: "read" | "write" | "save",
117
- message: string,
118
- public readonly path?: string,
119
- context?: Record<string, unknown>,
120
- ) {
121
- const details = [`Failed to ${operation} file`];
122
- if (path) {
123
- details.push(`Path: ${path}`);
124
- }
125
- details.push(message);
126
-
127
- super(
128
- details.join(". "),
129
- TagLibErrorCode.FILE_OPERATION_FAILED,
130
- { ...context, operation, path },
131
- );
132
- this.name = "FileOperationError";
133
- Object.setPrototypeOf(this, FileOperationError.prototype);
134
- }
135
- }
136
-
137
- /**
138
- * Error thrown when metadata operations fail
139
- */
140
- export class MetadataError extends TagLibError {
141
- constructor(
142
- public readonly operation: "read" | "write",
143
- message: string,
144
- public readonly field?: string,
145
- context?: Record<string, unknown>,
146
- ) {
147
- const details = [`Failed to ${operation} metadata`];
148
- if (field) {
149
- details.push(`Field: ${field}`);
150
- }
151
- details.push(message);
152
-
153
- super(
154
- details.join(". "),
155
- TagLibErrorCode.METADATA_ERROR,
156
- { ...context, operation, field },
157
- );
158
- this.name = "MetadataError";
159
- Object.setPrototypeOf(this, MetadataError.prototype);
160
- }
161
- }
162
-
163
- /**
164
- * Error thrown when Wasm memory operations fail
165
- */
166
- export class MemoryError extends TagLibError {
167
- constructor(message: string, context?: Record<string, unknown>) {
168
- super(
169
- createErrorMessage("Memory allocation failed", message),
170
- TagLibErrorCode.MEMORY_ERROR,
171
- context,
172
- );
173
- this.name = "MemoryError";
174
- Object.setPrototypeOf(this, MemoryError.prototype);
175
- }
176
- }
177
-
178
- /**
179
- * Error thrown when the environment doesn't support required features
180
- */
181
- export class EnvironmentError extends TagLibError {
182
- constructor(
183
- public readonly environment: string,
184
- message: string,
185
- public readonly requiredFeature?: string,
186
- context?: Record<string, unknown>,
187
- ) {
188
- const details = [`Environment '${environment}' ${message}`];
189
- if (requiredFeature) {
190
- details.push(`Required feature: ${requiredFeature}`);
191
- }
192
-
193
- super(
194
- details.join(". "),
195
- TagLibErrorCode.ENVIRONMENT_ERROR,
196
- { ...context, environment, requiredFeature },
197
- );
198
- this.name = "EnvironmentError";
199
- Object.setPrototypeOf(this, EnvironmentError.prototype);
200
- }
201
- }
202
-
203
- /**
204
- * Helper function to create consistent error messages
205
- */
206
- function createErrorMessage(prefix: string, details: string): string {
207
- return `${prefix}: ${details}`;
208
- }
209
-
210
- /**
211
- * Format file size in human-readable format
212
- */
213
- function formatFileSize(bytes: number): string {
214
- if (bytes < 1024) return `${bytes} bytes`;
215
- if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
216
- return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
217
- }
218
-
219
- /**
220
- * Type guards for error handling
221
- */
222
- export function isTagLibError(error: unknown): error is TagLibError {
223
- return error instanceof TagLibError;
224
- }
225
-
226
- export function isInvalidFormatError(
227
- error: unknown,
228
- ): error is InvalidFormatError {
229
- return error instanceof InvalidFormatError;
230
- }
231
-
232
- export function isUnsupportedFormatError(
233
- error: unknown,
234
- ): error is UnsupportedFormatError {
235
- return error instanceof UnsupportedFormatError;
236
- }
237
-
238
- export function isFileOperationError(
239
- error: unknown,
240
- ): error is FileOperationError {
241
- return error instanceof FileOperationError;
242
- }
243
-
244
- export function isMetadataError(error: unknown): error is MetadataError {
245
- return error instanceof MetadataError;
246
- }
247
-
248
- export function isMemoryError(error: unknown): error is MemoryError {
249
- return error instanceof MemoryError;
250
- }
251
-
252
- export function isEnvironmentError(error: unknown): error is EnvironmentError {
253
- return error instanceof EnvironmentError;
254
- }