@vidispine/vdt-js 23.4.0-pre.2 → 23.4.0-pre.4

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/index.d.ts CHANGED
@@ -4,6 +4,8 @@
4
4
  * @packageDocumentation
5
5
  */
6
6
 
7
+ /// <reference types="node" />
8
+
7
9
  import type { AudioComponentType } from '@vidispine/types';
8
10
  import type { BinaryComponentType } from '@vidispine/types';
9
11
  import type { CollectionType } from '@vidispine/types';
@@ -30,6 +32,271 @@ import type { VideoComponentType } from '@vidispine/types';
30
32
 
31
33
  declare type ArrayElement<ArrayType> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
32
34
 
35
+ /**
36
+ * Representation of a chunk sent by `ChunkUpload`
37
+ *
38
+ * @category Upload
39
+ */
40
+ export declare class Chunk {
41
+ state: ChunkState;
42
+ eventBus: ChunkedUploadEventBus;
43
+ tryTimeout: NodeJS.Timeout;
44
+ transferPromise: any;
45
+ start: number;
46
+ end: number;
47
+ fileSize: number;
48
+ blobSlice: any;
49
+ api: {
50
+ method?: (options: {
51
+ file: any;
52
+ onUploadProgress: (progressEvent: {
53
+ loaded: number;
54
+ }) => void;
55
+ headers?: {
56
+ index: number;
57
+ size: number;
58
+ };
59
+ }) => any;
60
+ props?: any;
61
+ };
62
+ constructor(props?: ChunkProps);
63
+ /**
64
+ * Attempt to transfer chunk with some fault resilience.
65
+ *
66
+ * - 3 retires with 1 second apart in case of failure
67
+ * - Pauses/resumes chunk transfer when network is offline/online
68
+ *
69
+ * @returns Promise of the transfer request
70
+ */
71
+ tryTransfer(): Promise<Chunk>;
72
+ /**
73
+ * Transfers `blobSlice` on this object with the `api.method`
74
+ *
75
+ * Triggers: `EVENTS.progress`
76
+ * Status: `STATUSES.transferring`
77
+ *
78
+ * @returns Promise for the transfer
79
+ */
80
+ transfer(): any;
81
+ pause(): void;
82
+ resume(): void;
83
+ cancel(): void;
84
+ get transferRate(): number;
85
+ private onComplete;
86
+ }
87
+
88
+ /**
89
+ * Class for sending and controlling multiple `ChunkedUpload` objects
90
+ *
91
+ * @category Upload
92
+ */
93
+ export declare class ChunkedTransferManager {
94
+ initialState: ChunkedTransferManagerState;
95
+ state: ChunkedTransferManagerState;
96
+ options: ChunkedTransferManagerOptions;
97
+ events: ChunkedUploadEventBus;
98
+ constructor(options?: ChunkedTransferManagerOptions);
99
+ get transfers(): ChunkedUpload[];
100
+ get status(): number;
101
+ set status(value: number);
102
+ get bytesTotal(): number;
103
+ get bytesDone(): number;
104
+ get isUploading(): boolean;
105
+ get paused(): boolean;
106
+ bindNetworkEvents(): void;
107
+ addChunkedUpload(chunkedUpload: ChunkedUpload): void;
108
+ removeChunkedUpload(InstanceOrFileOrTransferId: ChunkedUpload | File | string, force?: boolean): void;
109
+ onProgress(): void;
110
+ onComplete(): void;
111
+ exists(file: File): ChunkedUpload;
112
+ isTransferAvailable(transfer: any): boolean;
113
+ pause(): Promise<any>;
114
+ resume(): void;
115
+ retry(): void;
116
+ upload(): void;
117
+ onFail(error: any, state: ChunkedUpload['state']): void;
118
+ reset(): void;
119
+ destroy(): void;
120
+ get hasCompleted(): boolean;
121
+ updateStats(): void;
122
+ get percentDone(): number;
123
+ get fileList(): any[];
124
+ }
125
+
126
+ export declare type ChunkedTransferManagerOptions = {
127
+ maxConcurrentFileTransfers: number;
128
+ autoResume: boolean;
129
+ };
130
+
131
+ export declare type ChunkedTransferManagerState = {
132
+ status: number;
133
+ transfers: ChunkedUpload[];
134
+ bytesDone: number;
135
+ bytesTotal: number;
136
+ lastStats: {
137
+ bytesDone: number;
138
+ bytesTotal: number;
139
+ };
140
+ };
141
+
142
+ /**
143
+ * Class for dividing blobs/files into chunks and sending them through the supplied `options.api.method`
144
+ *
145
+ * @category Upload
146
+ */
147
+ export declare class ChunkedUpload {
148
+ readonly DEFAULT_OPTIONS: ChunkedUploadOptions;
149
+ eventBus: ChunkedUploadEventBus;
150
+ options: ChunkedUploadOptions;
151
+ state: ChunkedUploadState;
152
+ constructor(file: File, options: ChunkedUploadOptions);
153
+ upload(): void;
154
+ getByteRangesForChunks(blob: Blob, chunkSize?: number): any[];
155
+ addChunksFromBlob(blob: Blob): void;
156
+ retry(): void;
157
+ resume(): void;
158
+ pause(): Promise<Chunk[]>;
159
+ cancel(): Promise<Chunk[]>;
160
+ autoAdjustMaxConcurrentTransfers(stats: any): void;
161
+ onProgress(): void;
162
+ onComplete(): void;
163
+ getStats(): {
164
+ totalChunks: number;
165
+ completedChunks: number;
166
+ totalBytes: number;
167
+ transferredBytes: number;
168
+ avgTransferRate: number;
169
+ concurrentTransfers: number;
170
+ };
171
+ set concurrentTransfers(int: any);
172
+ set rate(int: number);
173
+ get rate(): number;
174
+ get finalResponse(): false | object;
175
+ get transferId(): string;
176
+ }
177
+
178
+ /**
179
+ * Event bus used by `Chunk`, `ChunkedUpload` and `ChunkedTransferManager` to communicate
180
+ *
181
+ * @category Upload
182
+ */
183
+ export declare class ChunkedUploadEventBus {
184
+ events: ChunkedUploadEventBusEvents;
185
+ constructor();
186
+ /**
187
+ * Add a callback for a specific event type
188
+ *
189
+ * @param event event type
190
+ * @param callback function receiving state of chunk, transfer manager or chunked upload instance
191
+ */
192
+ on(event: EVENTS, callback: (data: Chunk['state'] | ChunkedTransferManager['state'] | ChunkedUpload['state'], error?: any) => void): void;
193
+ /**
194
+ * Remove all callbacks for a specific event type
195
+ *
196
+ * @param event event type
197
+ */
198
+ off(event: EVENTS): void;
199
+ /**
200
+ * Trigger callbacks for a specific event
201
+ *
202
+ * @param event
203
+ * @param data
204
+ * @returns
205
+ */
206
+ trigger(event: EVENTS, data: Chunk['state'] | ChunkedTransferManager['state'] | ChunkedUpload['state'], error?: any): void;
207
+ }
208
+
209
+ export declare type ChunkedUploadEventBusEvents = {
210
+ [key in EVENTS]?: Array<(data: Chunk['state'] | ChunkedTransferManager['state'] | ChunkedUpload['state'], error?: any) => void>;
211
+ };
212
+
213
+ export declare type ChunkedUploadOptions = {
214
+ targetRate?: number;
215
+ chunkSize?: number;
216
+ minChunkSize?: number;
217
+ maxConcurrentTransfers?: number;
218
+ maxConcurrentFileTransfers?: number;
219
+ autoMaxConcurrentTransfers?: boolean;
220
+ minFileSize?: number;
221
+ api?: {
222
+ props?: {
223
+ pathParams?: {
224
+ [key: string]: any;
225
+ };
226
+ queryParams?: {
227
+ transferId?: string;
228
+ [key: string]: any;
229
+ };
230
+ data?: any;
231
+ };
232
+ method?: any;
233
+ [key: string]: any;
234
+ };
235
+ /**
236
+ * ChunkedTransferManager -> automatically resume transfers when network connection become active
237
+ */
238
+ autoResume?: boolean;
239
+ onComplete?: (finalResponse?: false | object) => void;
240
+ onProgress?: (stats?: ChunkedUploadStats) => void;
241
+ onFail?: (error?: any) => void;
242
+ };
243
+
244
+ export declare type ChunkedUploadState = {
245
+ blob: {
246
+ name: string;
247
+ lastModified: number;
248
+ size: number;
249
+ };
250
+ chunks: Chunk[];
251
+ status: number;
252
+ transferPromises: Promise<Chunk>[];
253
+ targetRate: number;
254
+ rate: number;
255
+ autoMaxConcurrentTransfers: boolean;
256
+ maxConcurrentTransfers: number;
257
+ mime: string;
258
+ transferId: string;
259
+ lastStats: {};
260
+ };
261
+
262
+ export declare type ChunkedUploadStats = {
263
+ totalChunks?: number;
264
+ completedChunks?: number;
265
+ totalBytes?: number;
266
+ transferredBytes?: number;
267
+ avgTransferRate?: number;
268
+ concurrentTransfers?: number;
269
+ };
270
+
271
+ export declare type ChunkProps = {
272
+ start?: number;
273
+ end?: number;
274
+ fileSize?: number;
275
+ blobSlice?: any;
276
+ api?: {
277
+ method?: (options?: {
278
+ file?: any;
279
+ onUploadProgress?: (progressEvent: {
280
+ loaded: number;
281
+ }) => void;
282
+ headers?: {
283
+ index: number;
284
+ size: number;
285
+ };
286
+ }) => any;
287
+ props?: any;
288
+ };
289
+ };
290
+
291
+ export declare type ChunkState = {
292
+ retries: number;
293
+ status: number;
294
+ startTime: number | null;
295
+ completeTime: number | null;
296
+ response: any;
297
+ bytesTransferred: number | null;
298
+ };
299
+
33
300
  /**
34
301
  * Create a VidiCore metadata object from a more dense/simplified structure
35
302
  *
@@ -83,8 +350,6 @@ export declare const createTimeCode: (timeCode: TimeCodeInput | string | number,
83
350
 
84
351
  export declare type CreateTimeCodeOptions = TimeCodeInputOptions | FormatTimeCodeSmpteOptions | FormatTimeCodeSecondsOptions | FormatTimeCodeTextOptions;
85
352
 
86
- export declare const defaultOptions: ParseSearchResultEventsOptions;
87
-
88
353
  /**
89
354
  * Const object with document types
90
355
  *
@@ -101,6 +366,27 @@ export declare const DOCUMENT_TYPES: {
101
366
  declare type DocumentType_2 = keyof typeof DOCUMENT_TYPES;
102
367
  export { DocumentType_2 as DocumentType }
103
368
 
369
+ /**
370
+ * Chunked upload event types
371
+ *
372
+ * @category Upload
373
+ */
374
+ export declare enum EVENTS {
375
+ progress = "progress",
376
+ update = "update",
377
+ complete = "complete",
378
+ error = "error",
379
+ added = "upload-added",
380
+ removed = "upload-removed",
381
+ failed = "upload-failed",
382
+ retry = "retry",
383
+ pausing = "pausing",
384
+ paused = "paused",
385
+ resuming = "resuming",
386
+ offline = "offline",
387
+ online = "online"
388
+ }
389
+
104
390
  /**
105
391
  * Array with all available metadata field attributes
106
392
  *
@@ -156,8 +442,38 @@ export declare const FILE_STATES: {
156
442
  readonly AWAITING_SYNC: "AWAITING_SYNC";
157
443
  };
158
444
 
445
+ export declare type FileLike = Partial<File> & {
446
+ path?: string;
447
+ };
448
+
449
+ /**
450
+ * Converts a list of files into a tree structure
451
+ *
452
+ * Works with `path` or the native `webkitRelativePath`
453
+ *
454
+ * @param files An array of file like objects
455
+ * @returns A file tree object
456
+ *
457
+ * @category Upload
458
+ */
459
+ export declare const fileListToFileTree: (files: FileLike[]) => {
460
+ [key: string]: FileTree;
461
+ };
462
+
159
463
  export declare type FileStateTypes = keyof typeof FILE_STATES;
160
464
 
465
+ export declare type FileTree = {
466
+ file: File;
467
+ path?: string;
468
+ progress?: {
469
+ totalBytes: number;
470
+ transferredBytes: number;
471
+ };
472
+ files?: {
473
+ [fileName: string]: FileTree;
474
+ };
475
+ };
476
+
161
477
  export declare type FilteredShapeListObject = {
162
478
  src: string;
163
479
  type: string;
@@ -253,6 +569,12 @@ export declare interface FormatTimeCodeSecondsOptions extends TimeCodeInputOptio
253
569
  * e.g. `1.04 => 104@100 => 26@25` (if no explicit `timeBase` is set)
254
570
  */
255
571
  useGCD?: boolean;
572
+ /**
573
+ * Select if it should floor, round or ceil if conforming seconds to the supplied timebase
574
+ *
575
+ * @default `'floor'`
576
+ */
577
+ roundingMode?: 'floor' | 'ceil' | 'round';
256
578
  }
257
579
 
258
580
  /**
@@ -303,6 +625,27 @@ export declare interface FormatTimeCodeTextOptions extends TimeCodeInputOptions
303
625
  */
304
626
  export declare const formatTimeCodeType: (timeCode: TimeCodeInput, options?: TimeCodeInputOptions) => TimeCode;
305
627
 
628
+ /**
629
+ * Filter a shape type list to get shapes that are playable in a browser
630
+ *
631
+ * The mime types "video/quicktime" & "video/x-m4v" are considered "video/mp4" if:
632
+ * 1. container format is "MPEG-4" or "mov"
633
+ * 2. video codec is "h264"
634
+ *
635
+ * @param itemType
636
+ * @param options
637
+ * @returns
638
+ *
639
+ * @category Shape
640
+ */
641
+ export declare const getPlayerSources: (itemType: ItemType, options?: GetPlayerSourcesOptions) => PlayerSource[];
642
+
643
+ export declare type GetPlayerSourcesOptions = {
644
+ allowedMimeTypes?: string[];
645
+ allowedMethods?: string[];
646
+ streamingServers?: string[];
647
+ };
648
+
306
649
  /**
307
650
  * Return a const for the document type of a shape (looks at mimeType)
308
651
  *
@@ -635,7 +978,7 @@ export declare type ParsedMetadataType<TOptions> = (TOptions extends {
635
978
  includeMetadataAttributes?: true | string[];
636
979
  } ? ParsedMetadataAttributes : {});
637
980
 
638
- export declare type ParsedSearchResultEntryTimespanType = {
981
+ declare type ParsedSearchResultEntryTimespanType = {
639
982
  entityType?: 'Item' | 'Collection';
640
983
  entityId?: string;
641
984
  group?: MetadataGroupValueType;
@@ -646,7 +989,7 @@ export declare type ParsedSearchResultEntryTimespanType = {
646
989
  endSeconds?: number;
647
990
  };
648
991
 
649
- export declare type ParsedSearchResultEntryType = {
992
+ declare type ParsedSearchResultEntryType = {
650
993
  entityType: 'Item' | 'Collection';
651
994
  entityId: string;
652
995
  events?: ParsedSearchResultEntryTimespanType[];
@@ -654,7 +997,7 @@ export declare type ParsedSearchResultEntryType = {
654
997
  collectionType?: CollectionType;
655
998
  };
656
999
 
657
- export declare type ParsedSearchResultEvents<TOptions> = TOptions extends {
1000
+ declare type ParsedSearchResultEvents<TOptions> = TOptions extends {
658
1001
  flatEvents?: true;
659
1002
  } ? ParsedSearchResultEntryTimespanType[] : ParsedSearchResultEntryType[];
660
1003
 
@@ -975,13 +1318,15 @@ export declare const parseNowDate: (value?: string) => Date;
975
1318
  * - https://apidoc.vidispine.com/latest/ref/search.html#search-collection-and-item-by-metadata-group
976
1319
  * - https://apidoc.vidispine.com/latest/item/search.html#find-item-and-collections-by-their-metadata-groups
977
1320
  *
978
- * @param searchResult
979
- * @param options
980
- * @returns
1321
+ * @param searchResult Metadata-group search results that should be parsed into events
1322
+ * @param options options for tweaking how search results should be parsed
1323
+ * @returns Search results converted to an array of more event-like objects
1324
+ *
1325
+ * @category Search
981
1326
  */
982
1327
  export declare const parseSearchResultEvents: <TOptions extends ParseSearchResultEventsOptions = ParseSearchResultEventsOptions>(searchResult?: SearchResultType, options?: TOptions) => ParsedSearchResultEvents<TOptions>;
983
1328
 
984
- export declare type ParseSearchResultEventsOptions = {
1329
+ declare type ParseSearchResultEventsOptions = {
985
1330
  /**
986
1331
  * Append matching group with metadata
987
1332
  */
@@ -1014,7 +1359,21 @@ export declare type ParseSearchResultEventsOptions = {
1014
1359
  *
1015
1360
  * @category Shape
1016
1361
  */
1017
- export declare const parseShapeType: (shapeType?: ShapeType) => ParsedShapeType;
1362
+ export declare const parseShapeType: (shapeType?: ShapeType, options?: ParseShapeTypeOptions) => ParsedShapeType;
1363
+
1364
+ declare type ParseShapeTypeOptions = {
1365
+ /**
1366
+ * Which component type to prioritize when merging and duplicate keys in components
1367
+ *
1368
+ * Default priority:
1369
+ * 1. 'container'
1370
+ * 2. 'video'
1371
+ * 3. 'audio'
1372
+ * 4. 'binary'
1373
+ *
1374
+ */
1375
+ priority?: ('container' | 'video' | 'audio' | 'binary')[];
1376
+ };
1018
1377
 
1019
1378
  /**
1020
1379
  * Parse simple (key/value) metadata
@@ -1114,6 +1473,13 @@ export declare type ParseValueOptions = {
1114
1473
  */
1115
1474
  export declare const parseVideoComponent: (videoComponentType?: VideoComponentType) => ParsedVideoComponentType;
1116
1475
 
1476
+ export declare type PlayerSource = {
1477
+ src: string;
1478
+ type: string;
1479
+ label: string;
1480
+ timeBase: string;
1481
+ };
1482
+
1117
1483
  /**
1118
1484
  * Const object with VidiCore role names
1119
1485
  *
@@ -1248,6 +1614,21 @@ export declare const SHAPE_MEDIA_TYPES: {
1248
1614
 
1249
1615
  export declare type ShapeMediaType = keyof typeof SHAPE_MEDIA_TYPES;
1250
1616
 
1617
+ /**
1618
+ * Chunked upload status types
1619
+ *
1620
+ * @category Upload
1621
+ */
1622
+ export declare enum STATUSES {
1623
+ transferring = 1,
1624
+ paused = 2,
1625
+ complete = 3,
1626
+ failed = 4,
1627
+ idle = 5,
1628
+ canceled = 6,
1629
+ offline = 7
1630
+ }
1631
+
1251
1632
  /**
1252
1633
  * Array with all available VidiCore system/default field group names
1253
1634
  *
@@ -1404,14 +1785,15 @@ export declare class TimeCode {
1404
1785
  * Creates a new TimeCode instance with specified timeBase and samples adjusted to that.
1405
1786
  *
1406
1787
  * @remarks
1407
- * If it conforms to a less granular time base - it will floor samples (hasn't reached that sample yet)
1788
+ * It floors samples when conforming to a less granular time base (can be changed with `options.mode`)
1789
+ *
1408
1790
  * - e.g. "51@50".conformTo("PAL") => "25@PAL" (not "26@PAL")
1409
1791
  *
1410
1792
  * @param timeBase The TimeBase it should conform the TimeCode to
1411
- * @param options Explicitly set TimeCode options, by default these are derived from `timeBase`
1793
+ * @param options Explicitly set conform options, by default these are derived from `timeBase`
1412
1794
  * @returns A new TimeCode instance with the conformTo timeBase applied
1413
1795
  */
1414
- conformTimeBase(timeBase: TimeCodeInput['timeBase'], options?: TimeCodeInputOptions): TimeCode;
1796
+ conformTimeBase(timeBase: TimeCodeInput['timeBase'], options?: TimeCodeConformOptions): TimeCode;
1415
1797
  /**
1416
1798
  * Get TimeCode as a text representation
1417
1799
  *
@@ -1464,7 +1846,7 @@ export declare class TimeCode {
1464
1846
  *
1465
1847
  * @returns Total seconds for the time code
1466
1848
  */
1467
- toSeconds(): number;
1849
+ toSeconds(options?: TimeCodeToSecondsOptions): number;
1468
1850
  /**
1469
1851
  * Get TimeCode in a duration representation
1470
1852
  *
@@ -1491,9 +1873,11 @@ export declare class TimeCode {
1491
1873
  /**
1492
1874
  * Get TimeCode in a smpte representation
1493
1875
  *
1876
+ * @param {Object} options
1877
+ * @param {boolean} options.uniformSeparators Use the frame separator for all separators in the smpte string
1494
1878
  * @returns Smpte representation of the TimeCode
1495
1879
  */
1496
- toSmpte(): string;
1880
+ toSmpte(options?: ToSmpteOptions): string;
1497
1881
  /**
1498
1882
  * Get TimeCode as a VidiCore TimeCodeType object
1499
1883
  *
@@ -1514,11 +1898,19 @@ export declare class TimeCode {
1514
1898
  };
1515
1899
  }
1516
1900
 
1901
+ export declare interface TimeCodeConformOptions extends TimeCodeInputOptions {
1902
+ /**
1903
+ * Set if conforming should floor, round or ceil samples when converting to a less granular timebase
1904
+ * @default `'floor'`
1905
+ */
1906
+ roundingMode?: 'floor' | 'ceil' | 'round';
1907
+ }
1908
+
1517
1909
  export declare type TimeCodeInput = {
1518
1910
  /** Amount of samples for the time code */
1519
1911
  samples?: number | string;
1520
1912
  /** The time base for the time code */
1521
- timeBase?: string | TimeBaseInput | TimeBase;
1913
+ timeBase?: string | number | TimeBaseInput | TimeBase;
1522
1914
  };
1523
1915
 
1524
1916
  export declare type TimeCodeInputOptions = {
@@ -1528,4 +1920,17 @@ export declare type TimeCodeInputOptions = {
1528
1920
  frameSeparator?: string;
1529
1921
  };
1530
1922
 
1923
+ declare type TimeCodeToSecondsOptions = {
1924
+ /**
1925
+ * Set true if seconds should be rounded with millisecond precision
1926
+ *
1927
+ * @default false
1928
+ */
1929
+ round?: boolean;
1930
+ };
1931
+
1932
+ declare type ToSmpteOptions = {
1933
+ uniformSeparators?: boolean;
1934
+ };
1935
+
1531
1936
  export { }