@prismatic-io/spectral 7.6.4 → 7.6.6

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.
@@ -21,6 +21,7 @@ exports.evaluate = exports.parseDate = exports.contains = exports.parseValue = e
21
21
  const types_1 = require("./types");
22
22
  const date_fns_1 = require("date-fns");
23
23
  const lodash_1 = __importDefault(require("lodash"));
24
+ const util_1 = __importDefault(require("../util"));
24
25
  const validate = (expression) => {
25
26
  if (!(expression instanceof Array)) {
26
27
  return [false, `Invalid expression syntax: '${expression}'`];
@@ -234,11 +235,11 @@ const evaluate = (expression) => {
234
235
  case types_1.BinaryOperator.doesNotEndWith:
235
236
  return !`${right}`.endsWith(`${left}`);
236
237
  case types_1.BinaryOperator.dateTimeAfter:
237
- return (0, date_fns_1.isAfter)(left, right);
238
+ return (0, date_fns_1.isAfter)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
238
239
  case types_1.BinaryOperator.dateTimeBefore:
239
- return (0, date_fns_1.isBefore)(left, right);
240
+ return (0, date_fns_1.isBefore)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
240
241
  case types_1.BinaryOperator.dateTimeSame:
241
- return left == right;
242
+ return (0, date_fns_1.isEqual)(util_1.default.types.toDate(left), util_1.default.types.toDate(right));
242
243
  default:
243
244
  throw new Error(`Invalid operator: '${operator}'`);
244
245
  }
@@ -40,15 +40,15 @@ export declare enum BinaryOperator {
40
40
  }
41
41
  export declare const BinaryOperatorPhrase: {
42
42
  equal: string;
43
+ exactlyMatches: string;
43
44
  notEqual: string;
45
+ doesNotExactlyMatch: string;
44
46
  greaterThan: string;
45
47
  greaterThanOrEqual: string;
46
48
  lessThan: string;
47
49
  lessThanOrEqual: string;
48
50
  in: string;
49
51
  notIn: string;
50
- exactlyMatches: string;
51
- doesNotExactlyMatch: string;
52
52
  startsWith: string;
53
53
  doesNotStartWith: string;
54
54
  endsWith: string;
@@ -60,15 +60,15 @@ export declare const BinaryOperatorPhrase: {
60
60
  export declare type TermOperator = UnaryOperator | BinaryOperator;
61
61
  export declare const TermOperatorPhrase: {
62
62
  equal: string;
63
+ exactlyMatches: string;
63
64
  notEqual: string;
65
+ doesNotExactlyMatch: string;
64
66
  greaterThan: string;
65
67
  greaterThanOrEqual: string;
66
68
  lessThan: string;
67
69
  lessThanOrEqual: string;
68
70
  in: string;
69
71
  notIn: string;
70
- exactlyMatches: string;
71
- doesNotExactlyMatch: string;
72
72
  startsWith: string;
73
73
  doesNotStartWith: string;
74
74
  endsWith: string;
@@ -47,20 +47,20 @@ var BinaryOperator;
47
47
  BinaryOperator["dateTimeSame"] = "dateTimeSame";
48
48
  })(BinaryOperator = exports.BinaryOperator || (exports.BinaryOperator = {}));
49
49
  exports.BinaryOperatorPhrase = {
50
- [BinaryOperator.equal]: "equal",
50
+ [BinaryOperator.equal]: "equals",
51
+ [BinaryOperator.exactlyMatches]: "exactly matches",
51
52
  [BinaryOperator.notEqual]: "does not equal",
53
+ [BinaryOperator.doesNotExactlyMatch]: "does not exactly match",
52
54
  [BinaryOperator.greaterThan]: "is greater than",
53
55
  [BinaryOperator.greaterThanOrEqual]: "is greater than or equal to",
54
56
  [BinaryOperator.lessThan]: "is less than",
55
57
  [BinaryOperator.lessThanOrEqual]: "is less than or equal to",
56
58
  [BinaryOperator.in]: "contained in",
57
59
  [BinaryOperator.notIn]: "not contained in",
58
- [BinaryOperator.exactlyMatches]: "exactly matches",
59
- [BinaryOperator.doesNotExactlyMatch]: "does not exactly match",
60
- [BinaryOperator.startsWith]: "starts with",
61
- [BinaryOperator.doesNotStartWith]: "does not start with",
62
- [BinaryOperator.endsWith]: "ends with",
63
- [BinaryOperator.doesNotEndWith]: "does not end with",
60
+ [BinaryOperator.startsWith]: "starts the string",
61
+ [BinaryOperator.doesNotStartWith]: "does not start the string",
62
+ [BinaryOperator.endsWith]: "ends the string",
63
+ [BinaryOperator.doesNotEndWith]: "does not end the string",
64
64
  [BinaryOperator.dateTimeAfter]: "is after (date/time)",
65
65
  [BinaryOperator.dateTimeBefore]: "is before (date/time)",
66
66
  [BinaryOperator.dateTimeSame]: "is the same (date/time)",
package/dist/util.js CHANGED
@@ -13,6 +13,7 @@ exports.toObject = exports.lowerCaseHeaders = void 0;
13
13
  const parseISO_1 = __importDefault(require("date-fns/parseISO"));
14
14
  const isValid_1 = __importDefault(require("date-fns/isValid"));
15
15
  const isDate_1 = __importDefault(require("date-fns/isDate"));
16
+ const fromUnixTime_1 = __importDefault(require("date-fns/fromUnixTime"));
16
17
  const safe_stable_stringify_1 = require("safe-stable-stringify");
17
18
  const valid_url_1 = require("valid-url");
18
19
  const isObjectWithTruthyKeys = (value, keys) => {
@@ -247,11 +248,12 @@ const toBigInt = (value) => {
247
248
  /** This function returns true if `value` is a variable of type `Date`, and false otherwise. */
248
249
  const isDate = (value) => (0, isDate_1.default)(value);
249
250
  /**
250
- * This function parses an ISO date if possible, or throws an error if the value provided
251
+ * This function parses an ISO date or UNIX epoch timestamp if possible, or throws an error if the value provided
251
252
  * cannot be coerced into a Date object.
252
253
  *
253
254
  * - `util.types.toDate(new Date('1995-12-17T03:24:00'))` will return `Date('1995-12-17T09:24:00.000Z')` since a `Date` object was passed in.
254
255
  * - `util.types.toDate('2021-03-20')` will return `Date('2021-03-20T05:00:00.000Z')` since a valid ISO date was passed in.
256
+ * - `util.types.toDate(1616198400) will return `Date('2021-03-20T00:00:00.000Z')` since a UNIX epoch timestamp was passed in.
255
257
  * - `parseISODate('2021-03-20-05')` will throw an error since `value` was not a valid ISO date.
256
258
  * @param value The value to turn into a date.
257
259
  * @returns The date equivalent of `value`.
@@ -260,6 +262,9 @@ const toDate = (value) => {
260
262
  if (isDate(value)) {
261
263
  return value;
262
264
  }
265
+ if (isNumber(value) && toNumber(value)) {
266
+ return (0, fromUnixTime_1.default)(toNumber(value));
267
+ }
263
268
  if (typeof value === "string") {
264
269
  const dt = (0, parseISO_1.default)(value);
265
270
  if ((0, isValid_1.default)(dt)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "7.6.4",
3
+ "version": "7.6.6",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"
@@ -40,7 +40,7 @@
40
40
  "@jsonforms/core": "3.0.0",
41
41
  "axios": "0.27.2",
42
42
  "axios-retry": "3.2.5",
43
- "date-fns": "2.29.3",
43
+ "date-fns": "2.30.0",
44
44
  "form-data": "4.0.0",
45
45
  "jest-mock": "27.0.3",
46
46
  "soap": "1.0.0",