@prismatic-io/spectral 7.0.15-pre → 7.0.16-pre
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/util.d.ts +2 -1
- package/dist/util.js +32 -0
- package/package.json +1 -1
package/dist/util.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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 } from "./types";
|
|
6
|
+
import { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap, JSONForm, ConnectionDefinition } from "./types";
|
|
7
7
|
/**
|
|
8
8
|
* This function returns a lower cased version of the headers passed to it.
|
|
9
9
|
*
|
|
@@ -45,6 +45,7 @@ declare const _default: {
|
|
|
45
45
|
toJSONForm: (value: unknown) => JSONForm;
|
|
46
46
|
isPicklist: (value: unknown) => boolean;
|
|
47
47
|
isSchedule: (value: unknown) => boolean;
|
|
48
|
+
isConnection: (value: unknown) => value is ConnectionDefinition;
|
|
48
49
|
};
|
|
49
50
|
docs: {
|
|
50
51
|
formatJsonExample: (input: unknown) => string;
|
package/dist/util.js
CHANGED
|
@@ -405,6 +405,37 @@ const isString = (value) => typeof value === "string" || value instanceof String
|
|
|
405
405
|
* @returns This function returns the stringified version fo `value`, or `defaultValue` in the case that `value` is undefined or an empty string.
|
|
406
406
|
*/
|
|
407
407
|
const toString = (value, defaultValue = "") => `${value !== null && value !== void 0 ? value : defaultValue}`;
|
|
408
|
+
/**
|
|
409
|
+
* This function checks if value is a valid connection.
|
|
410
|
+
* @param value The variable to test.
|
|
411
|
+
* @returns This function returns true or false, depending on if `value` is a valid connection.
|
|
412
|
+
*/
|
|
413
|
+
const isConnection = (value) => {
|
|
414
|
+
if (typeof value === "string" && isJSON(value)) {
|
|
415
|
+
return isConnection(JSON.parse(value));
|
|
416
|
+
}
|
|
417
|
+
if (Boolean(value) && typeof value === "object") {
|
|
418
|
+
const { inputs } = value;
|
|
419
|
+
if (isObjectWithTruthyKeys(value, ["key", "label", "oauth2Type"])) {
|
|
420
|
+
return (isObjectWithTruthyKeys(inputs, [
|
|
421
|
+
"authorizeUrl",
|
|
422
|
+
"tokenUrl",
|
|
423
|
+
"scopes",
|
|
424
|
+
"clientId",
|
|
425
|
+
"clientSecret",
|
|
426
|
+
]) ||
|
|
427
|
+
isObjectWithTruthyKeys(inputs, [
|
|
428
|
+
"tokenUrl",
|
|
429
|
+
"scopes",
|
|
430
|
+
"clientId",
|
|
431
|
+
"clientSecret",
|
|
432
|
+
]));
|
|
433
|
+
}
|
|
434
|
+
return (isObjectWithTruthyKeys(value, ["key", "label"]) &&
|
|
435
|
+
typeof inputs === "object");
|
|
436
|
+
}
|
|
437
|
+
return false;
|
|
438
|
+
};
|
|
408
439
|
/**
|
|
409
440
|
* This function returns true if `value` resembles the shape of JSON, and false otherwise.
|
|
410
441
|
*
|
|
@@ -478,6 +509,7 @@ exports.default = {
|
|
|
478
509
|
toJSONForm,
|
|
479
510
|
isPicklist,
|
|
480
511
|
isSchedule,
|
|
512
|
+
isConnection,
|
|
481
513
|
},
|
|
482
514
|
docs: {
|
|
483
515
|
formatJsonExample,
|