1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.isRootType = exports.copyOwnProps = exports.copyOwnPropsIfNotPresent = exports.isObject = exports.makeRef = exports.takeRandom = exports.randomListLength = exports.uuidv4 = void 0;
|
4 | const utils_1 = require("@graphql-tools/utils");
|
5 | function uuidv4() {
|
6 | return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
7 | const r = (Math.random() * 16) | 0;
|
8 |
|
9 | const v = c == 'x' ? r : (r & 0x3) | 0x8;
|
10 | return v.toString(16);
|
11 | });
|
12 | }
|
13 | exports.uuidv4 = uuidv4;
|
14 | const randomListLength = () => {
|
15 |
|
16 |
|
17 | return 2;
|
18 | };
|
19 | exports.randomListLength = randomListLength;
|
20 | const takeRandom = (arr) => arr[Math.floor(Math.random() * arr.length)];
|
21 | exports.takeRandom = takeRandom;
|
22 | function makeRef(typeName, key) {
|
23 | return { $ref: { key, typeName } };
|
24 | }
|
25 | exports.makeRef = makeRef;
|
26 | function isObject(thing) {
|
27 | return thing === Object(thing) && !Array.isArray(thing);
|
28 | }
|
29 | exports.isObject = isObject;
|
30 | function copyOwnPropsIfNotPresent(target, source) {
|
31 | for (const prop of Object.getOwnPropertyNames(source)) {
|
32 | if (!Object.getOwnPropertyDescriptor(target, prop)) {
|
33 | const propertyDescriptor = Object.getOwnPropertyDescriptor(source, prop);
|
34 | Object.defineProperty(target, prop, propertyDescriptor == null ? {} : propertyDescriptor);
|
35 | }
|
36 | }
|
37 | }
|
38 | exports.copyOwnPropsIfNotPresent = copyOwnPropsIfNotPresent;
|
39 | function copyOwnProps(target, ...sources) {
|
40 | for (const source of sources) {
|
41 | let chain = source;
|
42 | while (chain != null) {
|
43 | copyOwnPropsIfNotPresent(target, chain);
|
44 | chain = Object.getPrototypeOf(chain);
|
45 | }
|
46 | }
|
47 | return target;
|
48 | }
|
49 | exports.copyOwnProps = copyOwnProps;
|
50 | const isRootType = (type, schema) => {
|
51 | const rootTypeNames = (0, utils_1.getRootTypeNames)(schema);
|
52 | return rootTypeNames.has(type.name);
|
53 | };
|
54 | exports.isRootType = isRootType;
|