rate-core 0.5.0 → 0.5.1

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/lib/index.js CHANGED
@@ -468,6 +468,38 @@ var RateValidator = (function () {
468
468
  return RateValidator;
469
469
  }());
470
470
  exports.RateValidator = RateValidator;
471
+ var RatesValidator = (function () {
472
+ function RatesValidator(attributes, check, max, length) {
473
+ this.attributes = attributes;
474
+ this.check = check;
475
+ this.max = max;
476
+ this.length = length;
477
+ this.validate = this.validate.bind(this);
478
+ }
479
+ RatesValidator.prototype.validate = function (rate) {
480
+ var errs = this.check(rate, this.attributes);
481
+ if (!rate.rates || rate.rates.length === 0) {
482
+ var err = createError('rates', 'required');
483
+ errs.push(err);
484
+ return Promise.resolve(errs);
485
+ }
486
+ if (rate.rates.length !== this.length) {
487
+ var err = createError('rates', 'length', this.length);
488
+ errs.push(err);
489
+ return Promise.resolve(errs);
490
+ }
491
+ for (var _i = 0, _a = rate.rates; _i < _a.length; _i++) {
492
+ var r = _a[_i];
493
+ if (r > this.max) {
494
+ var err = createError('rates', 'max', this.max);
495
+ errs.push(err);
496
+ }
497
+ }
498
+ return Promise.resolve(errs);
499
+ };
500
+ return RatesValidator;
501
+ }());
502
+ exports.RatesValidator = RatesValidator;
471
503
  function createError(field, code, param) {
472
504
  if (!code) {
473
505
  code = 'string';
package/lib/rate.js CHANGED
@@ -143,6 +143,7 @@ exports.ratesModel = {
143
143
  type: 'number'
144
144
  },
145
145
  rates: {
146
+ required: true,
146
147
  type: 'integers'
147
148
  },
148
149
  time: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rate-core",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "rate",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -355,6 +355,32 @@ export class RateValidator {
355
355
  }
356
356
  }
357
357
  }
358
+ // tslint:disable-next-line:max-classes-per-file
359
+ export class RatesValidator {
360
+ constructor(protected attributes: Attributes, protected check: (obj: any, attributes: Attributes) => ErrorMessage[], protected max: number, protected length: number) {
361
+ this.validate = this.validate.bind(this);
362
+ }
363
+ validate(rate: Rates): Promise<ErrorMessage[]> {
364
+ const errs = this.check(rate, this.attributes);
365
+ if (!rate.rates || rate.rates.length === 0) {
366
+ const err = createError('rates', 'required');
367
+ errs.push(err);
368
+ return Promise.resolve(errs);
369
+ }
370
+ if (rate.rates.length !== this.length) {
371
+ const err = createError('rates', 'length', this.length);
372
+ errs.push(err);
373
+ return Promise.resolve(errs);
374
+ }
375
+ for (const r of rate.rates) {
376
+ if (r > this.max) {
377
+ const err = createError('rates', 'max', this.max);
378
+ errs.push(err);
379
+ }
380
+ }
381
+ return Promise.resolve(errs);
382
+ }
383
+ }
358
384
  function createError(field: string, code?: string, param?: string | number | Date): ErrorMessage {
359
385
  if (!code) {
360
386
  code = 'string';
package/src/rate.ts CHANGED
@@ -309,6 +309,7 @@ export const ratesModel: Attributes = {
309
309
  type: 'number'
310
310
  },
311
311
  rates: {
312
+ required: true,
312
313
  type: 'integers'
313
314
  },
314
315
  time: {