Skip to content

Commit e59a5ba

Browse files
authored
fix(es5): replace ajv with jsonschema in transform validator
* fix(es5): replace ajv with jsonschema in transform validator Replace es6 library with es5 compatybile and add gzip to minimalize bundle size BREAKING CHANGE: Validation errors from transform are updated to ValidationError from jsonschema * feat(Gzip): Add info about gzip support in README * ci(publish script): Udpate publish script for supporting gzip ContentEncoding
1 parent 8b69edd commit e59a5ba

File tree

9 files changed

+1518
-2221
lines changed

9 files changed

+1518
-2221
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ const client = filestack.init('apikey');
4242
const client = filestack.init('apikey');
4343
</script>
4444
```
45+
**GZIP support**
46+
```HTML
47+
To speed up library loading you can use gzipped file available after adding gz before the file extension
48+
49+
<script src="//static.filestackapi.com/filestack-js/1.x.x/filestack.min.gz.js"></script>
50+
<script>
51+
const client = filestack.init('apikey');
52+
</script>
53+
```
4554

4655
### Node
4756

package-lock.json

Lines changed: 1428 additions & 2128 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@
4343
},
4444
"dependencies": {
4545
"abab": "^2.0.0",
46-
"ajv": "^6.5.5",
4746
"file-type": "^8.1.0",
4847
"filestack-loader": "^3.0.4",
4948
"is-svg": "^3.0.0",
5049
"isutf8": "^2.0.2",
50+
"jsonschema": "^1.2.4",
5151
"spark-md5": "^3.0.0",
5252
"superagent": "^3.8.3",
5353
"tcomb-validation": "^3.4.1",
5454
"tslib": "^1.9.3"
5555
},
5656
"devDependencies": {
57-
"@babel/core": "^7.2.2",
58-
"@babel/preset-env": "^7.3.1",
57+
"@babel/core": "^7.3.4",
58+
"@babel/preset-env": "^7.3.4",
5959
"@types/mime": "^2.0.0",
6060
"@types/mocha": "^2.2.48",
6161
"@types/node": "^10.5.2",
@@ -76,6 +76,7 @@
7676
"gh-pages": "^1.2.0",
7777
"gulp": "^4.0.0",
7878
"gulp-better-rollup": "3.1.0",
79+
"gulp-gzip": "^1.4.2",
7980
"gulp-rename": "^1.4.0",
8081
"gulp-replace": "^1.0.0",
8182
"gulp-rollup": "^2.16.2",
@@ -97,7 +98,7 @@
9798
"mime-types": "^2.1.19",
9899
"mocha": "^5.2.0",
99100
"npm-run-all": "^4.1.5",
100-
"nyc": "^13.1.0",
101+
"nyc": "^13.3.0",
101102
"opn-cli": "^3.1.0",
102103
"rollup": "^0.57.0",
103104
"rollup-plugin-alias": "^1.4.0",
@@ -115,11 +116,12 @@
115116
"trash-cli": "^1.4.0",
116117
"tslint": "^5.11.0",
117118
"tslint-config-semistandard": "^7.0.0",
118-
"typedoc": "^0.11.1",
119+
"typedoc": "^0.14.2",
119120
"typescript": "^2.9.2",
120121
"uglify-es": "^3.3.10",
122+
"url": "^0.11.0",
121123
"validate-commit-msg": "^2.14.0",
122-
"watchify": "^3.11.0"
124+
"watchify": "^3.11.1"
123125
},
124126
"keywords": [
125127
"filestack",

scripts/build.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const rollupConfig = require('../rollup.config')
1212
const version = require('../package.json').version;
1313
const uglify = composer(uglifyEs);
1414
const rename = require('gulp-rename');
15+
const gzip = require('gulp-gzip');
1516

1617
// const debug = require('gulp-debug');
1718
gulp.task('build:clean', function () {
@@ -84,4 +85,10 @@ gulp.task('build:uglify', gulp.series('build:rollup', () => {
8485

8586
gulp.task('build', gulp.series(['build:clean', 'build:rollup']));
8687

87-
gulp.task('build:prod', gulp.series(['build:clean', 'build:uglify']));
88+
gulp.task('build:prod', gulp.series(['build:clean', 'build:uglify', () => {
89+
return gulp.src(['build/browser/filestack.min.js'])
90+
.pipe(gzip({
91+
preExtension: 'gz'
92+
}))
93+
.pipe(gulp.dest('build/browser'));
94+
}]));

scripts/publish.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@ const getFilesToBeUploaded = (from) => {
3535
const pushOneFileToS3 = (file, to) => {
3636
return new Promise((resolve, reject) => {
3737
const path = `${to.folder}/${file.path}`;
38-
s3.putObject({
38+
const isGzip = file.path.indexOf('gz') > -1;
39+
40+
const options = {
3941
Bucket: to.bucket,
4042
Key: path,
4143
Body: file.content,
4244
ContentType: figureOutFileMimetype(file),
43-
}, (err) => {
45+
};
46+
47+
if (isGzip) {
48+
options['ContentEncoding'] = 'gzip';
49+
}
50+
51+
s3.putObject(options, (err) => {
4452
if (err) {
4553
console.error('Upload ERROR:', err);
4654
reject(err);

src/lib/filelink.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,9 @@ export class Filelink {
12071207
const toValidate = {};
12081208
toValidate[name] = options;
12091209

1210-
if (!this.validator(toValidate)) {
1211-
throw new FilestackError(`Task "${name}" validation error, Params: ${JSON.stringify(options)}`, this.validator.errors);
1210+
const res = this.validator(toValidate);
1211+
if (res.errors.length) {
1212+
throw new FilestackError(`Task "${name}" validation error, Params: ${JSON.stringify(options)}`, res.errors);
12121213
}
12131214

12141215
return;

src/schema/transforms.schema.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ import { getValidator, TransformSchema } from './';
2020

2121
describe('Transforms Schema', () => {
2222

23-
const validate = getValidator(TransformSchema);
23+
const validator = getValidator(TransformSchema);
2424

25-
const assertFail = (val) => assert.ok(!val);
25+
const validate = (params) => {
26+
const res = validator(params);
27+
return res.errors.length === 0 ? true : false;
28+
};
29+
30+
const assertFail = (res) => assert.ok(!res);
2631

2732
it('should load json schema', () => {
2833
// console.log(schema);

0 commit comments

Comments
 (0)