@prismatic-io/spectral 7.6.5 → 7.6.7

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
  }
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)) {
@@ -313,14 +318,12 @@ const keyValPairListToObject = (kvpList, valueConverter) => {
313
318
  };
314
319
  /**
315
320
  * This function tests if the object provided is a Prismatic `DataPayload` object.
316
- * A `DataPayload` object is an object with a `data` attribute, and optional `contentType` attribute.
321
+ * A `DataPayload` object is an object with a `data` attribute that is a Buffer, and optional `contentType` attribute.
317
322
  *
318
323
  * @param value The value to test
319
324
  * @returns This function returns true if `value` is a DataPayload object, and false otherwise.
320
325
  */
321
- const isBufferDataPayload = (value) => {
322
- return value instanceof Object && "data" in value;
323
- };
326
+ const isBufferDataPayload = (value) => value instanceof Object && "data" in value && Buffer.isBuffer(value["data"]);
324
327
  /**
325
328
  * Many libraries for third-party API that handle binary files expect `Buffer` objects.
326
329
  * This function helps to convert strings, Uint8Arrays, and Arrays to a data structure
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "7.6.5",
3
+ "version": "7.6.7",
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",