@deenruv/reviews-plugin 1.0.17-dev.18 → 1.0.17-dev.23

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.
@@ -1,12 +1,12 @@
1
1
  /* eslint-disable */
2
- import { AllTypesProps, ReturnTypes, Ops } from './const.js';
3
- export const HOST = "http://localhost:6100/admin-api";
2
+ import { AllTypesProps, ReturnTypes, Ops } from "./const.js";
3
+ export const HOST = "Specify host";
4
4
  export const HEADERS = {};
5
5
  export const apiSubscription = (options) => (query) => {
6
6
  var _a, _b, _c;
7
7
  try {
8
- const queryString = options[0] + '?query=' + encodeURIComponent(query);
9
- const wsString = queryString.replace('http', 'ws');
8
+ const queryString = options[0] + "?query=" + encodeURIComponent(query);
9
+ const wsString = queryString.replace("http", "ws");
10
10
  const host = (options.length > 1 && ((_b = (_a = options[1]) === null || _a === void 0 ? void 0 : _a.websocket) === null || _b === void 0 ? void 0 : _b[0])) || wsString;
11
11
  const webSocketOptions = ((_c = options[1]) === null || _c === void 0 ? void 0 : _c.websocket) || [host];
12
12
  const ws = new WebSocket(...webSocketOptions);
@@ -33,7 +33,7 @@ export const apiSubscription = (options) => (query) => {
33
33
  };
34
34
  }
35
35
  catch (_d) {
36
- throw new Error('No websockets implemented');
36
+ throw new Error("No websockets implemented");
37
37
  }
38
38
  };
39
39
  const handleFetchResponse = (response) => {
@@ -56,7 +56,7 @@ const handleFetchResponse = (response) => {
56
56
  };
57
57
  export const apiFetch = (options) => (query, variables = {}) => {
58
58
  const fetchOptions = options[1] || {};
59
- if (fetchOptions.method && fetchOptions.method === 'GET') {
59
+ if (fetchOptions.method && fetchOptions.method === "GET") {
60
60
  return fetch(`${options[0]}?query=${encodeURIComponent(query)}`, fetchOptions)
61
61
  .then(handleFetchResponse)
62
62
  .then((response) => {
@@ -66,8 +66,8 @@ export const apiFetch = (options) => (query, variables = {}) => {
66
66
  return response.data;
67
67
  });
68
68
  }
69
- return fetch(`${options[0]}`, Object.assign({ body: JSON.stringify({ query, variables }), method: 'POST', headers: {
70
- 'Content-Type': 'application/json',
69
+ return fetch(`${options[0]}`, Object.assign({ body: JSON.stringify({ query, variables }), method: "POST", headers: {
70
+ "Content-Type": "application/json",
71
71
  } }, fetchOptions))
72
72
  .then(handleFetchResponse)
73
73
  .then((response) => {
@@ -78,17 +78,17 @@ export const apiFetch = (options) => (query, variables = {}) => {
78
78
  });
79
79
  };
80
80
  export const InternalsBuildQuery = ({ ops, props, returns, options, scalars, }) => {
81
- const ibb = (k, o, p = '', root = true, vars = []) => {
81
+ const ibb = (k, o, p = "", root = true, vars = []) => {
82
82
  var _a;
83
83
  const keyForPath = purifyGraphQLKey(k);
84
84
  const newPath = [p, keyForPath].join(SEPARATOR);
85
85
  if (!o) {
86
- return '';
86
+ return "";
87
87
  }
88
- if (typeof o === 'boolean' || typeof o === 'number') {
88
+ if (typeof o === "boolean" || typeof o === "number") {
89
89
  return k;
90
90
  }
91
- if (typeof o === 'string') {
91
+ if (typeof o === "string") {
92
92
  return `${k} ${o}`;
93
93
  }
94
94
  if (Array.isArray(o)) {
@@ -101,29 +101,32 @@ export const InternalsBuildQuery = ({ ops, props, returns, options, scalars, })
101
101
  })(o[0], newPath);
102
102
  return `${ibb(args ? `${k}(${args})` : k, o[1], p, false, vars)}`;
103
103
  }
104
- if (k === '__alias') {
104
+ if (k === "__alias") {
105
105
  return Object.entries(o)
106
106
  .map(([alias, objectUnderAlias]) => {
107
- if (typeof objectUnderAlias !== 'object' || Array.isArray(objectUnderAlias)) {
108
- throw new Error('Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}');
107
+ if (typeof objectUnderAlias !== "object" ||
108
+ Array.isArray(objectUnderAlias)) {
109
+ throw new Error("Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}");
109
110
  }
110
111
  const operationName = Object.keys(objectUnderAlias)[0];
111
112
  const operation = objectUnderAlias[operationName];
112
113
  return ibb(`${alias}:${operationName}`, operation, p, false, vars);
113
114
  })
114
- .join('\n');
115
+ .join("\n");
115
116
  }
116
- const hasOperationName = root && (options === null || options === void 0 ? void 0 : options.operationName) ? ' ' + options.operationName : '';
117
- const keyForDirectives = (_a = o.__directives) !== null && _a !== void 0 ? _a : '';
117
+ const hasOperationName = root && (options === null || options === void 0 ? void 0 : options.operationName) ? " " + options.operationName : "";
118
+ const keyForDirectives = (_a = o.__directives) !== null && _a !== void 0 ? _a : "";
118
119
  const query = `{${Object.entries(o)
119
- .filter(([k]) => k !== '__directives')
120
+ .filter(([k]) => k !== "__directives")
120
121
  .map((e) => ibb(...e, [p, `field<>${keyForPath}`].join(SEPARATOR), false, vars))
121
- .join('\n')}}`;
122
+ .join("\n")}}`;
122
123
  if (!root) {
123
124
  return `${k} ${keyForDirectives}${hasOperationName} ${query}`;
124
125
  }
125
- const varsString = vars.map((v) => `${v.name}: ${v.graphQLType}`).join(', ');
126
- return `${k} ${keyForDirectives}${hasOperationName}${varsString ? `(${varsString})` : ''} ${query}`;
126
+ const varsString = vars
127
+ .map((v) => `${v.name}: ${v.graphQLType}`)
128
+ .join(", ");
129
+ return `${k} ${keyForDirectives}${hasOperationName}${varsString ? `(${varsString})` : ""} ${query}`;
127
130
  };
128
131
  return ibb;
129
132
  };
@@ -183,7 +186,7 @@ export const ZeusSelect = () => ((t) => t);
183
186
  export const Selector = (key) => key && ZeusSelect();
184
187
  export const TypeFromSelector = (key) => key && ZeusSelect();
185
188
  export const Gql = Chain(HOST, {
186
- headers: Object.assign({ 'Content-Type': 'application/json' }, HEADERS),
189
+ headers: Object.assign({ "Content-Type": "application/json" }, HEADERS),
187
190
  });
188
191
  export const ZeusScalars = ZeusSelect();
189
192
  export const decodeScalarsInResponse = ({ response, scalars, returns, ops, initialZeusQuery, initialOp, }) => {
@@ -213,12 +216,15 @@ export const traverseResponse = ({ resolvers, scalarPaths, }) => {
213
216
  const scalarPathString = p.join(SEPARATOR);
214
217
  const currentScalarString = scalarPaths[scalarPathString];
215
218
  if (currentScalarString) {
216
- const currentDecoder = (_a = resolvers[currentScalarString.split('.')[1]]) === null || _a === void 0 ? void 0 : _a.decode;
219
+ const currentDecoder = (_a = resolvers[currentScalarString.split(".")[1]]) === null || _a === void 0 ? void 0 : _a.decode;
217
220
  if (currentDecoder) {
218
221
  return currentDecoder(o);
219
222
  }
220
223
  }
221
- if (typeof o === 'boolean' || typeof o === 'number' || typeof o === 'string' || !o) {
224
+ if (typeof o === "boolean" ||
225
+ typeof o === "number" ||
226
+ typeof o === "string" ||
227
+ !o) {
222
228
  return o;
223
229
  }
224
230
  const entries = Object.entries(o).map(([k, v]) => [k, ibb(k, v, [...p, purifyGraphQLKey(k)])]);
@@ -230,15 +236,15 @@ export const traverseResponse = ({ resolvers, scalarPaths, }) => {
230
236
  };
231
237
  return ibb;
232
238
  };
233
- export const SEPARATOR = '|';
239
+ export const SEPARATOR = "|";
234
240
  export class GraphQLError extends Error {
235
241
  constructor(response) {
236
- super('');
242
+ super("");
237
243
  this.response = response;
238
244
  console.error(response);
239
245
  }
240
246
  toString() {
241
- return 'GraphQL Response Error';
247
+ return "GraphQL Response Error";
242
248
  }
243
249
  }
244
250
  const ExtractScalar = (mappedParts, returns) => {
@@ -247,7 +253,7 @@ const ExtractScalar = (mappedParts, returns) => {
247
253
  }
248
254
  const oKey = mappedParts[0];
249
255
  const returnP1 = returns[oKey];
250
- if (typeof returnP1 === 'object') {
256
+ if (typeof returnP1 === "object") {
251
257
  const returnP2 = returnP1[mappedParts[1]];
252
258
  if (returnP2) {
253
259
  return ExtractScalar([returnP2, ...mappedParts.slice(2)], returns);
@@ -256,15 +262,17 @@ const ExtractScalar = (mappedParts, returns) => {
256
262
  }
257
263
  return returnP1;
258
264
  };
259
- export const PrepareScalarPaths = ({ ops, returns }) => {
265
+ export const PrepareScalarPaths = ({ ops, returns, }) => {
260
266
  const ibb = (k, originalKey, o, p = [], pOriginals = [], root = true) => {
261
267
  if (!o) {
262
268
  return;
263
269
  }
264
- if (typeof o === 'boolean' || typeof o === 'number' || typeof o === 'string') {
270
+ if (typeof o === "boolean" ||
271
+ typeof o === "number" ||
272
+ typeof o === "string") {
265
273
  const extractionArray = [...pOriginals, originalKey];
266
274
  const isScalar = ExtractScalar(extractionArray, returns);
267
- if (isScalar === null || isScalar === void 0 ? void 0 : isScalar.startsWith('scalar')) {
275
+ if (isScalar === null || isScalar === void 0 ? void 0 : isScalar.startsWith("scalar")) {
268
276
  const partOfTree = {
269
277
  [[...p, k].join(SEPARATOR)]: isScalar,
270
278
  };
@@ -275,11 +283,12 @@ export const PrepareScalarPaths = ({ ops, returns }) => {
275
283
  if (Array.isArray(o)) {
276
284
  return ibb(k, k, o[1], p, pOriginals, false);
277
285
  }
278
- if (k === '__alias') {
286
+ if (k === "__alias") {
279
287
  return Object.entries(o)
280
288
  .map(([alias, objectUnderAlias]) => {
281
- if (typeof objectUnderAlias !== 'object' || Array.isArray(objectUnderAlias)) {
282
- throw new Error('Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}');
289
+ if (typeof objectUnderAlias !== "object" ||
290
+ Array.isArray(objectUnderAlias)) {
291
+ throw new Error("Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}");
283
292
  }
284
293
  const operationName = Object.keys(objectUnderAlias)[0];
285
294
  const operation = objectUnderAlias[operationName];
@@ -289,57 +298,61 @@ export const PrepareScalarPaths = ({ ops, returns }) => {
289
298
  }
290
299
  const keyName = root ? ops[k] : k;
291
300
  return Object.entries(o)
292
- .filter(([k]) => k !== '__directives')
301
+ .filter(([k]) => k !== "__directives")
293
302
  .map(([k, v]) => {
294
303
  // Inline fragments shouldn't be added to the path as they aren't a field
295
304
  const isInlineFragment = originalKey.match(/^...\s*on/) != null;
296
- return ibb(k, k, v, isInlineFragment ? p : [...p, purifyGraphQLKey(keyName || k)], isInlineFragment ? pOriginals : [...pOriginals, purifyGraphQLKey(originalKey)], false);
305
+ return ibb(k, k, v, isInlineFragment ? p : [...p, purifyGraphQLKey(keyName || k)], isInlineFragment
306
+ ? pOriginals
307
+ : [...pOriginals, purifyGraphQLKey(originalKey)], false);
297
308
  })
298
309
  .reduce((a, b) => (Object.assign(Object.assign({}, a), b)));
299
310
  };
300
311
  return ibb;
301
312
  };
302
- export const purifyGraphQLKey = (k) => k.replace(/\([^)]*\)/g, '').replace(/^[^:]*\:/g, '');
313
+ export const purifyGraphQLKey = (k) => k.replace(/\([^)]*\)/g, "").replace(/^[^:]*\:/g, "");
303
314
  const mapPart = (p) => {
304
- const [isArg, isField] = p.split('<>');
315
+ const [isArg, isField] = p.split("<>");
305
316
  if (isField) {
306
317
  return {
307
318
  v: isField,
308
- __type: 'field',
319
+ __type: "field",
309
320
  };
310
321
  }
311
322
  return {
312
323
  v: isArg,
313
- __type: 'arg',
324
+ __type: "arg",
314
325
  };
315
326
  };
316
327
  export const ResolveFromPath = (props, returns, ops) => {
317
328
  const ResolvePropsType = (mappedParts) => {
318
329
  const oKey = ops[mappedParts[0].v];
319
330
  const propsP1 = oKey ? props[oKey] : props[mappedParts[0].v];
320
- if (propsP1 === 'enum' && mappedParts.length === 1) {
321
- return 'enum';
331
+ if (propsP1 === "enum" && mappedParts.length === 1) {
332
+ return "enum";
322
333
  }
323
- if (typeof propsP1 === 'string' && propsP1.startsWith('scalar.') && mappedParts.length === 1) {
334
+ if (typeof propsP1 === "string" &&
335
+ propsP1.startsWith("scalar.") &&
336
+ mappedParts.length === 1) {
324
337
  return propsP1;
325
338
  }
326
- if (typeof propsP1 === 'object') {
339
+ if (typeof propsP1 === "object") {
327
340
  if (mappedParts.length < 2) {
328
- return 'not';
341
+ return "not";
329
342
  }
330
343
  const propsP2 = propsP1[mappedParts[1].v];
331
- if (typeof propsP2 === 'string') {
344
+ if (typeof propsP2 === "string") {
332
345
  return rpp(`${propsP2}${SEPARATOR}${mappedParts
333
346
  .slice(2)
334
347
  .map((mp) => mp.v)
335
348
  .join(SEPARATOR)}`);
336
349
  }
337
- if (typeof propsP2 === 'object') {
350
+ if (typeof propsP2 === "object") {
338
351
  if (mappedParts.length < 3) {
339
- return 'not';
352
+ return "not";
340
353
  }
341
354
  const propsP3 = propsP2[mappedParts[2].v];
342
- if (propsP3 && mappedParts[2].__type === 'arg') {
355
+ if (propsP3 && mappedParts[2].__type === "arg") {
343
356
  return rpp(`${propsP3}${SEPARATOR}${mappedParts
344
357
  .slice(3)
345
358
  .map((mp) => mp.v)
@@ -350,13 +363,13 @@ export const ResolveFromPath = (props, returns, ops) => {
350
363
  };
351
364
  const ResolveReturnType = (mappedParts) => {
352
365
  if (mappedParts.length === 0) {
353
- return 'not';
366
+ return "not";
354
367
  }
355
368
  const oKey = ops[mappedParts[0].v];
356
369
  const returnP1 = oKey ? returns[oKey] : returns[mappedParts[0].v];
357
- if (typeof returnP1 === 'object') {
370
+ if (typeof returnP1 === "object") {
358
371
  if (mappedParts.length < 2)
359
- return 'not';
372
+ return "not";
360
373
  const returnP2 = returnP1[mappedParts[1].v];
361
374
  if (returnP2) {
362
375
  return rpp(`${returnP2}${SEPARATOR}${mappedParts
@@ -377,16 +390,18 @@ export const ResolveFromPath = (props, returns, ops) => {
377
390
  if (returnP1) {
378
391
  return returnP1;
379
392
  }
380
- return 'not';
393
+ return "not";
381
394
  };
382
395
  return rpp;
383
396
  };
384
397
  export const InternalArgsBuilt = ({ props, ops, returns, scalars, vars, }) => {
385
- const arb = (a, p = '', root = true) => {
398
+ const arb = (a, p = "", root = true) => {
386
399
  var _a, _b;
387
- if (typeof a === 'string') {
400
+ if (typeof a === "string") {
388
401
  if (a.startsWith(START_VAR_NAME)) {
389
- const [varName, graphQLType] = a.replace(START_VAR_NAME, '$').split(GRAPHQL_TYPE_SEPARATOR);
402
+ const [varName, graphQLType] = a
403
+ .replace(START_VAR_NAME, "$")
404
+ .split(GRAPHQL_TYPE_SEPARATOR);
390
405
  const v = vars.find((v) => v.name === varName);
391
406
  if (!v) {
392
407
  vars.push({
@@ -403,29 +418,29 @@ export const InternalArgsBuilt = ({ props, ops, returns, scalars, vars, }) => {
403
418
  }
404
419
  }
405
420
  const checkType = ResolveFromPath(props, returns, ops)(p);
406
- if (checkType.startsWith('scalar.')) {
421
+ if (checkType.startsWith("scalar.")) {
407
422
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
408
- const [_, ...splittedScalar] = checkType.split('.');
409
- const scalarKey = splittedScalar.join('.');
423
+ const [_, ...splittedScalar] = checkType.split(".");
424
+ const scalarKey = splittedScalar.join(".");
410
425
  return ((_b = (_a = scalars === null || scalars === void 0 ? void 0 : scalars[scalarKey]) === null || _a === void 0 ? void 0 : _a.encode) === null || _b === void 0 ? void 0 : _b.call(_a, a)) || JSON.stringify(a);
411
426
  }
412
427
  if (Array.isArray(a)) {
413
- return `[${a.map((arr) => arb(arr, p, false)).join(', ')}]`;
428
+ return `[${a.map((arr) => arb(arr, p, false)).join(", ")}]`;
414
429
  }
415
- if (typeof a === 'string') {
416
- if (checkType === 'enum') {
430
+ if (typeof a === "string") {
431
+ if (checkType === "enum") {
417
432
  return a;
418
433
  }
419
434
  return `${JSON.stringify(a)}`;
420
435
  }
421
- if (typeof a === 'object') {
436
+ if (typeof a === "object") {
422
437
  if (a === null) {
423
438
  return `null`;
424
439
  }
425
440
  const returnedObjectString = Object.entries(a)
426
- .filter(([, v]) => typeof v !== 'undefined')
441
+ .filter(([, v]) => typeof v !== "undefined")
427
442
  .map(([k, v]) => `${k}: ${arb(v, [p, k].join(SEPARATOR), false)}`)
428
- .join(',\n');
443
+ .join(",\n");
429
444
  if (!root) {
430
445
  return `{${returnedObjectString}}`;
431
446
  }
@@ -439,5 +454,8 @@ export const resolverFor = (type, field, fn) => fn;
439
454
  export const START_VAR_NAME = `$ZEUS_VAR`;
440
455
  export const GRAPHQL_TYPE_SEPARATOR = `__$GRAPHQL__`;
441
456
  export const $ = (name, graphqlType) => {
442
- return (START_VAR_NAME + name + GRAPHQL_TYPE_SEPARATOR + graphqlType);
457
+ return (START_VAR_NAME +
458
+ name +
459
+ GRAPHQL_TYPE_SEPARATOR +
460
+ graphqlType);
443
461
  };