1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.assertSome = exports.isSome = exports.compareNodes = exports.nodeToString = exports.compareStrings = exports.isValidPath = exports.isDocumentString = exports.asArray = void 0;
|
4 | const graphql_1 = require("graphql");
|
5 | const asArray = (fns) => (Array.isArray(fns) ? fns : fns ? [fns] : []);
|
6 | exports.asArray = asArray;
|
7 | const invalidDocRegex = /\.[a-z0-9]+$/i;
|
8 | function isDocumentString(str) {
|
9 | if (typeof str !== 'string') {
|
10 | return false;
|
11 | }
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | if (invalidDocRegex.test(str)) {
|
18 | return false;
|
19 | }
|
20 | try {
|
21 | (0, graphql_1.parse)(str);
|
22 | return true;
|
23 | }
|
24 | catch (e) { }
|
25 | return false;
|
26 | }
|
27 | exports.isDocumentString = isDocumentString;
|
28 | const invalidPathRegex = /[‘“!%^<>`\n]/;
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | function isValidPath(str) {
|
38 | return typeof str === 'string' && !invalidPathRegex.test(str);
|
39 | }
|
40 | exports.isValidPath = isValidPath;
|
41 | function compareStrings(a, b) {
|
42 | if (String(a) < String(b)) {
|
43 | return -1;
|
44 | }
|
45 | if (String(a) > String(b)) {
|
46 | return 1;
|
47 | }
|
48 | return 0;
|
49 | }
|
50 | exports.compareStrings = compareStrings;
|
51 | function nodeToString(a) {
|
52 | let name;
|
53 | if ('alias' in a) {
|
54 | name = a.alias?.value;
|
55 | }
|
56 | if (name == null && 'name' in a) {
|
57 | name = a.name?.value;
|
58 | }
|
59 | if (name == null) {
|
60 | name = a.kind;
|
61 | }
|
62 | return name;
|
63 | }
|
64 | exports.nodeToString = nodeToString;
|
65 | function compareNodes(a, b, customFn) {
|
66 | const aStr = nodeToString(a);
|
67 | const bStr = nodeToString(b);
|
68 | if (typeof customFn === 'function') {
|
69 | return customFn(aStr, bStr);
|
70 | }
|
71 | return compareStrings(aStr, bStr);
|
72 | }
|
73 | exports.compareNodes = compareNodes;
|
74 | function isSome(input) {
|
75 | return input != null;
|
76 | }
|
77 | exports.isSome = isSome;
|
78 | function assertSome(input, message = 'Value should be something') {
|
79 | if (input == null) {
|
80 | throw new Error(message);
|
81 | }
|
82 | }
|
83 | exports.assertSome = assertSome;
|