Skip to content

Commit c2709bf

Browse files
author
Nir Maoz
authored
Feature/concatenate to json (#501)
1 parent 98a09b5 commit c2709bf

File tree

14 files changed

+130
-26
lines changed

14 files changed

+130
-26
lines changed

__TESTS_BUNDLE_SIZE__/bundleSizeTestCases.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import importFromPackage from "./utils/stringGenerators/importFromPackage";
1515
const bundleSizeTestCases:ITestCase[] = [
1616
{
1717
name: 'Tests CloudinaryImage with Resize',
18-
sizeLimitInKB: 25,
18+
sizeLimitInKB: 26,
1919
importsArray: [
2020
importFromDist('assets/CloudinaryImage', 'CloudinaryImage'),
2121
importFromDist('instance/Cloudinary', 'Cloudinary'),
@@ -24,7 +24,7 @@ const bundleSizeTestCases:ITestCase[] = [
2424
},
2525
{
2626
name: 'Tests CloudinaryImage with Resize and Adjust',
27-
sizeLimitInKB: 29,
27+
sizeLimitInKB: 30,
2828
importsArray: [
2929
importFromDist('assets/CloudinaryImage', 'CloudinaryImage'),
3030
importFromDist('instance/Cloudinary', 'Cloudinary'),
@@ -88,7 +88,7 @@ const bundleSizeTestCases:ITestCase[] = [
8888
},
8989
{
9090
name: 'Import All Actions',
91-
sizeLimitInKB: 43,
91+
sizeLimitInKB: 44,
9292
importsArray: [
9393
importFromPackage('Actions')
9494
]

__TESTS__/unit/fromJson/concatenate.fromJson.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('concatenate.fromJson', () => {
66
const concatenateModel: IConcatenateActionModel = {
77
actionType: 'concatenate',
88
source: {
9-
qualifierType: 'videoSource',
9+
qualifierType: 'VideoSource',
1010
sourceType: 'video',
1111
publicId: 'dog'
1212
},
@@ -18,4 +18,26 @@ describe('concatenate.fromJson', () => {
1818

1919
expect(transformation.toString()).toStrictEqual('du_1,fl_splice,l_video:dog/fl_layer_apply,so_0');
2020
});
21+
22+
it('Should generate ConcatenateAction with transition from model', ()=>{
23+
const concatenateModel: IConcatenateActionModel = {
24+
actionType: 'concatenate',
25+
source: {
26+
qualifierType: 'VideoSource',
27+
sourceType: 'video',
28+
publicId: 'dog'
29+
},
30+
prepend: true,
31+
duration: 1,
32+
transition: {
33+
qualifierType: 'VideoSource',
34+
sourceType: 'video',
35+
publicId: 'cat'
36+
}
37+
};
38+
39+
const transformation = fromJson([concatenateModel]);
40+
41+
expect(transformation.toString()).toStrictEqual('du_1,l_video:dog/e_transition,l_video:cat/fl_layer_apply/fl_layer_apply,so_0');
42+
});
2143
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {Transformation} from '../../../src';
2+
import {Concatenate} from "../../../src/qualifiers/concatenate";
3+
import {VideoEdit} from "../../../src/actions";
4+
5+
describe('concatenate.toJson()', () => {
6+
it('Concatenate + prepend + duration + transition', () => {
7+
const transformation = new Transformation()
8+
.videoEdit(VideoEdit.concatenate(Concatenate.videoSource('dog'))
9+
.prepend()
10+
.duration(1)
11+
.transition(Concatenate.videoSource('cat'))
12+
);
13+
expect(transformation.toJson()).toStrictEqual([
14+
{
15+
actionType: 'concatenate',
16+
source: {
17+
qualifierType: 'VideoSource',
18+
sourceType: 'video',
19+
publicId: 'dog'
20+
},
21+
prepend: true,
22+
duration: 1,
23+
transition: {
24+
qualifierType: 'VideoSource',
25+
sourceType: 'video',
26+
publicId: 'cat'
27+
}
28+
}
29+
]);
30+
});
31+
});

src/actions/videoEdit/ConcatenateAction.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {FetchSource} from "../../qualifiers/source/sourceTypes/FetchSource.js";
66
import {IActionModel} from "../../internal/models/IActionModel.js";
77
import {IConcatenateActionModel} from "../../internal/models/IConcatenateActionModel.js";
88
import {ITransformationFromJson} from "../../internal/models/IHasFromJson.js";
9+
import {IVideoSourceModel} from "../../internal/models/IVideoSourceModel.js";
910

1011
/**
1112
* @description Class for Concatenating another video.
@@ -31,7 +32,7 @@ class ConcatenateAction extends Action {
3132
super();
3233
this._actionModel = {
3334
actionType: 'concatenate',
34-
source: { sourceType: 'video' }
35+
source: source.toJson() as IVideoSourceModel
3536
};
3637

3738
this.concatSource = source;
@@ -43,6 +44,7 @@ class ConcatenateAction extends Action {
4344
* @return {this}
4445
*/
4546
transition(source: VideoSource): this {
47+
this._actionModel.transition = source.toJson() as IVideoSourceModel;
4648
this._transition = source;
4749
return this;
4850
}
@@ -52,6 +54,7 @@ class ConcatenateAction extends Action {
5254
* @return {this}
5355
*/
5456
prepend(): this {
57+
this._actionModel.prepend = true;
5558
this._prepend = true;
5659
return this;
5760
}
@@ -62,6 +65,7 @@ class ConcatenateAction extends Action {
6265
* @return {this}
6366
*/
6467
duration(sec: number): this {
68+
this._actionModel.duration = sec;
6569
this._duration = sec;
6670
return this;
6771
}

src/internal/Action.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ import {FlagQualifier} from "../qualifiers/flag/FlagQualifier.js";
22
import {Qualifier} from "./qualifier/Qualifier.js";
33
import {mapToSortedArray} from "./utils/dataStructureUtils.js";
44
import {FlagTypes} from "../types/types.js";
5-
import {IActionModel} from "./models/IActionModel.js";
6-
import {IErrorObject} from "./models/IErrorObject.js";
7-
import {createUnsupportedError} from "./utils/unsupportedError.js";
5+
import {ActionModel} from "./models/ActionModel.js";
86

97
/**
108
* @summary SDK
119
* @memberOf SDK
1210
* @description Defines the category of transformation to perform.
1311
*/
14-
class Action {
15-
protected _actionModel: IActionModel = {}; // Action model representation
16-
12+
class Action extends ActionModel {
1713
// We're using map, to overwrite existing keys. for example:
1814
// addParam(w_100).addQualifier(w_200) should result in w_200. and not w_100,w_200
1915
qualifiers: Map<string, Qualifier> = new Map();
@@ -23,7 +19,8 @@ class Action {
2319
// So flags are stored separately until the very end because of that reason
2420
flags: FlagQualifier[] = [];
2521
private delimiter = ','; // {qualifier}{delimiter}{qualifier} for example: `${'w_100'}${','}${'c_fill'}`
26-
protected prepareQualifiers():void {}
22+
protected prepareQualifiers(): void {}
23+
2724
private actionTag = ''; // A custom name tag to identify this action in the future
2825

2926
/**
@@ -38,7 +35,7 @@ class Action {
3835
* @description Sets the custom name tag for this action
3936
* @return {this}
4037
*/
41-
setActionTag(tag:string): this {
38+
setActionTag(tag: string): this {
4239
this.actionTag = tag;
4340
return this;
4441
}
@@ -96,15 +93,7 @@ class Action {
9693
return this;
9794
}
9895

99-
toJson(): IActionModel | IErrorObject{
100-
if (this._actionModel.actionType){
101-
return this._actionModel;
102-
}
103-
104-
return {error: createUnsupportedError(`unsupported action ${this.constructor.name}`)};
105-
}
106-
107-
protected addValueToQualifier(qualifierKey: string, qualifierValue: any): this{
96+
protected addValueToQualifier(qualifierKey: string, qualifierValue: any): this {
10897
this.qualifiers.get(qualifierKey).addValue(qualifierValue);
10998

11099
return this;

src/internal/models/ActionModel.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {IActionModel} from "./IActionModel.js";
2+
import {actionToJson} from "./actionToJson.js";
3+
4+
export class ActionModel {
5+
protected _actionModel: IActionModel;
6+
toJson = actionToJson;
7+
8+
constructor() {
9+
this._actionModel = {};
10+
}
11+
}

src/internal/models/IVideoSourceModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {ISourceModel} from "./ISourceModel.js";
22
import {IVideoTransformationModel} from "./IVideoTransformationModel.js";
33

44
export interface IVideoSourceModel extends ISourceModel {
5-
qualifierType: "videoSource";
5+
qualifierType: "VideoSource";
66
sourceType: "video";
77
publicId: string;
88
transformation?: IVideoTransformationModel;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {IQualifierModel} from "../models/IQualifierModel.js";
2+
import {qualifierToJson} from "../models/qualifierToJson.js";
3+
4+
export class QualifierModel{
5+
_qualifierModel: IQualifierModel;
6+
toJson = qualifierToJson;
7+
8+
constructor() {
9+
this._qualifierModel = {};
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {IActionModel} from "./IActionModel.js";
2+
import {IErrorObject} from "./IErrorObject.js";
3+
import {createUnsupportedError} from "../utils/unsupportedError.js";
4+
5+
/**
6+
* Returns the action's model
7+
*/
8+
export function actionToJson(): IActionModel | IErrorObject {
9+
if (this._actionModel && this._actionModel.actionType) {
10+
return this._actionModel;
11+
}
12+
13+
return {error: createUnsupportedError(`unsupported action ${this.constructor.name}`)};
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {IErrorObject} from "./IErrorObject.js";
2+
import {createUnsupportedError} from "../utils/unsupportedError.js";
3+
import {IQualifierModel} from "./IQualifierModel.js";
4+
5+
/**
6+
* Returns the action's model
7+
*/
8+
export function qualifierToJson(): IQualifierModel | IErrorObject {
9+
if (this._qualifierModel && this._qualifierModel.qualifierType) {
10+
return this._qualifierModel;
11+
}
12+
13+
return {error: createUnsupportedError(`unsupported qualifier ${this.constructor.name}`)};
14+
}

0 commit comments

Comments
 (0)