@prismatic-io/spectral 7.1.0 → 7.2.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/dist/index.d.ts +1 -1
- package/dist/testing.d.ts +2 -2
- package/dist/types/DataSourceResult.d.ts +2 -2
- package/dist/util.d.ts +16 -7
- package/dist/util.js +35 -18
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/testing.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare const invokeDataSource: <TInputs extends Inputs, TDataSourceType
|
|
|
43
43
|
string: string;
|
|
44
44
|
date: string;
|
|
45
45
|
timestamp: string;
|
|
46
|
-
picklist: string[];
|
|
46
|
+
picklist: string[] | import("./types").Element[];
|
|
47
47
|
schedule: {
|
|
48
48
|
value: string;
|
|
49
49
|
};
|
|
@@ -76,7 +76,7 @@ declare const _default: {
|
|
|
76
76
|
string: string;
|
|
77
77
|
date: string;
|
|
78
78
|
timestamp: string;
|
|
79
|
-
picklist: string[];
|
|
79
|
+
picklist: string[] | import("./types").Element[];
|
|
80
80
|
schedule: {
|
|
81
81
|
value: string;
|
|
82
82
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ConnectionDefinition } from "./ConnectionDefinition";
|
|
2
|
-
import { ObjectSelection, ObjectFieldMap, JSONForm } from "./Inputs";
|
|
2
|
+
import { ObjectSelection, ObjectFieldMap, JSONForm, Element } from "./Inputs";
|
|
3
3
|
/** The type of field that is appropriate for rendering the data that is the result of the data source perform function. */
|
|
4
4
|
declare type DataSourceTypeMap = {
|
|
5
5
|
string: string;
|
|
6
6
|
date: string;
|
|
7
7
|
timestamp: string;
|
|
8
|
-
picklist: string[];
|
|
8
|
+
picklist: string[] | Element[];
|
|
9
9
|
schedule: {
|
|
10
10
|
value: string;
|
|
11
11
|
};
|
package/dist/util.d.ts
CHANGED
|
@@ -3,17 +3,27 @@
|
|
|
3
3
|
* Many functions in the `util` module are used to coerce data into a particular type, and can be accessed through `util.types`.
|
|
4
4
|
* For example, `util.types.toInt("5.5")` will return an integer, `5`.
|
|
5
5
|
*/
|
|
6
|
-
import { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap, JSONForm, ConnectionDefinition } from "./types";
|
|
6
|
+
import { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap, JSONForm, ConnectionDefinition, Element } from "./types";
|
|
7
7
|
/**
|
|
8
8
|
* This function returns a lower cased version of the headers passed to it.
|
|
9
9
|
*
|
|
10
|
-
* - `lowerCaseHeaders({"Content-Type": "Application/JSON"}) will return {"content-type": "Application/JSON"}`
|
|
11
|
-
* - `lowerCaseHeaders({"Cache-Control": "max-age=604800"}) will return {"cache-control": "max-age=604800"}`
|
|
12
|
-
* - `lowerCaseHeaders({"Accept-Language": "en-us"}) will return {"accept-language": "en-us"}`
|
|
10
|
+
* - `lowerCaseHeaders({"Content-Type": "Application/JSON"})` will return `{"content-type": "Application/JSON"}`
|
|
11
|
+
* - `lowerCaseHeaders({"Cache-Control": "max-age=604800"})` will return `{"cache-control": "max-age=604800"}`
|
|
12
|
+
* - `lowerCaseHeaders({"Accept-Language": "en-us"})` will return `{"accept-language": "en-us"}`
|
|
13
13
|
* @param headers The headers to convert to lower case
|
|
14
14
|
* @returns This function returns a header object
|
|
15
15
|
* */
|
|
16
16
|
export declare const lowerCaseHeaders: (headers: Record<string, string>) => Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* This function parses a JSON string (if JSON) and returns an object, or returns the object.
|
|
19
|
+
*
|
|
20
|
+
* - `toObject('{"foo":"bar","baz":123}')` will return object `{foo: "bar", baz: 123}`
|
|
21
|
+
* - `toObject({foo:"bar",baz:123})` will return object `{foo: "bar", baz: 123}`
|
|
22
|
+
*
|
|
23
|
+
* @param value The JSON string or object to convert
|
|
24
|
+
* @returns This function returns an object, parsing JSON as necessary
|
|
25
|
+
*/
|
|
26
|
+
export declare const toObject: (value: unknown) => object;
|
|
17
27
|
declare const _default: {
|
|
18
28
|
types: {
|
|
19
29
|
isBool: (value: unknown) => value is boolean;
|
|
@@ -46,9 +56,8 @@ declare const _default: {
|
|
|
46
56
|
isPicklist: (value: unknown) => boolean;
|
|
47
57
|
isSchedule: (value: unknown) => boolean;
|
|
48
58
|
isConnection: (value: unknown) => value is ConnectionDefinition;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
formatJsonExample: (input: unknown) => string;
|
|
59
|
+
isElement: (value: unknown) => value is Element;
|
|
60
|
+
toObject: (value: unknown) => object;
|
|
52
61
|
};
|
|
53
62
|
};
|
|
54
63
|
export default _default;
|
package/dist/util.js
CHANGED
|
@@ -8,7 +8,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
8
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.lowerCaseHeaders = void 0;
|
|
11
|
+
exports.toObject = exports.lowerCaseHeaders = void 0;
|
|
12
12
|
/** */
|
|
13
13
|
const parseISO_1 = __importDefault(require("date-fns/parseISO"));
|
|
14
14
|
const isValid_1 = __importDefault(require("date-fns/isValid"));
|
|
@@ -20,6 +20,13 @@ const isObjectWithTruthyKeys = (value, keys) => {
|
|
|
20
20
|
typeof value === "object" &&
|
|
21
21
|
keys.every((key) => key in value && Boolean(value === null || value === void 0 ? void 0 : value[key])));
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* This function checks if value is an Element.
|
|
25
|
+
* `util.types.isElement({key: "foo"})` and `util.types.isElement({key: "foo", label: "Foo"})` return true.
|
|
26
|
+
* @param value The variable to test.
|
|
27
|
+
* @returns This function returns true or false, depending on if `value` is an Element.
|
|
28
|
+
*/
|
|
29
|
+
const isElement = (value) => isObjectWithTruthyKeys(value, ["key"]);
|
|
23
30
|
/**
|
|
24
31
|
* @param value The value to test
|
|
25
32
|
* @returns This function returns true if the type of `value` is an ObjectSelection, or false otherwise.
|
|
@@ -57,9 +64,7 @@ const isObjectFieldMap = (value) => {
|
|
|
57
64
|
const { fields } = value;
|
|
58
65
|
return (Array.isArray(fields) &&
|
|
59
66
|
fields.every((item) => isObjectWithTruthyKeys(item, ["field"]) &&
|
|
60
|
-
|
|
61
|
-
"key",
|
|
62
|
-
])));
|
|
67
|
+
isElement(item === null || item === void 0 ? void 0 : item.field)));
|
|
63
68
|
}
|
|
64
69
|
return false;
|
|
65
70
|
};
|
|
@@ -281,7 +286,7 @@ const isUrl = (value) => (0, valid_url_1.isWebUri)(value) !== undefined;
|
|
|
281
286
|
* @param value The variable to test.
|
|
282
287
|
* @returns This function returns true if `value` is a valid picklist.
|
|
283
288
|
*/
|
|
284
|
-
const isPicklist = (value) => Array.isArray(value) && value.every(isString);
|
|
289
|
+
const isPicklist = (value) => Array.isArray(value) && (value.every(isString) || value.every(isElement));
|
|
285
290
|
/**
|
|
286
291
|
* This function checks if value is a valid schedule.
|
|
287
292
|
*
|
|
@@ -379,12 +384,6 @@ const isData = (value) => isBufferDataPayload(value);
|
|
|
379
384
|
* @returns This function returns an object with two keys: `data`, which is a `Buffer`, and `contentType`, which is a string.
|
|
380
385
|
*/
|
|
381
386
|
const toData = (value) => toBufferDataPayload(value);
|
|
382
|
-
/**
|
|
383
|
-
* This function helps to format JSON examples for documentation.
|
|
384
|
-
* @param input An object to be JSONified.
|
|
385
|
-
* @returns This function returns a code block that can be used for documentation.
|
|
386
|
-
*/
|
|
387
|
-
const formatJsonExample = (input) => ["```json", JSON.stringify(input, undefined, 2), "```"].join("\n");
|
|
388
387
|
/**
|
|
389
388
|
* This function checks if value is a string.
|
|
390
389
|
* `util.types.isString("value")` and `util.types.isString(new String("value"))` return true.
|
|
@@ -450,7 +449,8 @@ const isJSON = (value) => {
|
|
|
450
449
|
return false;
|
|
451
450
|
}
|
|
452
451
|
};
|
|
453
|
-
/**
|
|
452
|
+
/**
|
|
453
|
+
* This function accepts an arbitrary object/value and safely serializes it (handles cyclic references).
|
|
454
454
|
*
|
|
455
455
|
* @param value Arbitrary object/value to serialize.
|
|
456
456
|
* @returns JSON serialized text that can be safely logged.
|
|
@@ -462,9 +462,9 @@ const toJSON = (value) => {
|
|
|
462
462
|
/**
|
|
463
463
|
* This function returns a lower cased version of the headers passed to it.
|
|
464
464
|
*
|
|
465
|
-
* - `lowerCaseHeaders({"Content-Type": "Application/JSON"}) will return {"content-type": "Application/JSON"}`
|
|
466
|
-
* - `lowerCaseHeaders({"Cache-Control": "max-age=604800"}) will return {"cache-control": "max-age=604800"}`
|
|
467
|
-
* - `lowerCaseHeaders({"Accept-Language": "en-us"}) will return {"accept-language": "en-us"}`
|
|
465
|
+
* - `lowerCaseHeaders({"Content-Type": "Application/JSON"})` will return `{"content-type": "Application/JSON"}`
|
|
466
|
+
* - `lowerCaseHeaders({"Cache-Control": "max-age=604800"})` will return `{"cache-control": "max-age=604800"}`
|
|
467
|
+
* - `lowerCaseHeaders({"Accept-Language": "en-us"})` will return `{"accept-language": "en-us"}`
|
|
468
468
|
* @param headers The headers to convert to lower case
|
|
469
469
|
* @returns This function returns a header object
|
|
470
470
|
* */
|
|
@@ -472,6 +472,24 @@ const lowerCaseHeaders = (headers) => Object.entries(headers).reduce((result, [k
|
|
|
472
472
|
return Object.assign(Object.assign({}, result), { [key.toLowerCase()]: val });
|
|
473
473
|
}, {});
|
|
474
474
|
exports.lowerCaseHeaders = lowerCaseHeaders;
|
|
475
|
+
/**
|
|
476
|
+
* This function parses a JSON string (if JSON) and returns an object, or returns the object.
|
|
477
|
+
*
|
|
478
|
+
* - `toObject('{"foo":"bar","baz":123}')` will return object `{foo: "bar", baz: 123}`
|
|
479
|
+
* - `toObject({foo:"bar",baz:123})` will return object `{foo: "bar", baz: 123}`
|
|
480
|
+
*
|
|
481
|
+
* @param value The JSON string or object to convert
|
|
482
|
+
* @returns This function returns an object, parsing JSON as necessary
|
|
483
|
+
*/
|
|
484
|
+
const toObject = (value) => {
|
|
485
|
+
if (typeof value === "string" && isJSON(value)) {
|
|
486
|
+
return JSON.parse(value);
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
return value;
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
exports.toObject = toObject;
|
|
475
493
|
exports.default = {
|
|
476
494
|
types: {
|
|
477
495
|
isBool,
|
|
@@ -504,8 +522,7 @@ exports.default = {
|
|
|
504
522
|
isPicklist,
|
|
505
523
|
isSchedule,
|
|
506
524
|
isConnection,
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
formatJsonExample,
|
|
525
|
+
isElement,
|
|
526
|
+
toObject: exports.toObject,
|
|
510
527
|
},
|
|
511
528
|
};
|