@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,11 +1,11 @@
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
  try {
7
- const queryString = options[0] + '?query=' + encodeURIComponent(query);
8
- const wsString = queryString.replace('http', 'ws');
7
+ const queryString = options[0] + "?query=" + encodeURIComponent(query);
8
+ const wsString = queryString.replace("http", "ws");
9
9
  const host = (options.length > 1 && options[1]?.websocket?.[0]) || wsString;
10
10
  const webSocketOptions = options[1]?.websocket || [host];
11
11
  const ws = new WebSocket(...webSocketOptions);
@@ -32,7 +32,7 @@ export const apiSubscription = (options) => (query) => {
32
32
  };
33
33
  }
34
34
  catch {
35
- throw new Error('No websockets implemented');
35
+ throw new Error("No websockets implemented");
36
36
  }
37
37
  };
38
38
  const handleFetchResponse = (response) => {
@@ -55,7 +55,7 @@ const handleFetchResponse = (response) => {
55
55
  };
56
56
  export const apiFetch = (options) => (query, variables = {}) => {
57
57
  const fetchOptions = options[1] || {};
58
- if (fetchOptions.method && fetchOptions.method === 'GET') {
58
+ if (fetchOptions.method && fetchOptions.method === "GET") {
59
59
  return fetch(`${options[0]}?query=${encodeURIComponent(query)}`, fetchOptions)
60
60
  .then(handleFetchResponse)
61
61
  .then((response) => {
@@ -67,9 +67,9 @@ export const apiFetch = (options) => (query, variables = {}) => {
67
67
  }
68
68
  return fetch(`${options[0]}`, {
69
69
  body: JSON.stringify({ query, variables }),
70
- method: 'POST',
70
+ method: "POST",
71
71
  headers: {
72
- 'Content-Type': 'application/json',
72
+ "Content-Type": "application/json",
73
73
  },
74
74
  ...fetchOptions,
75
75
  })
@@ -82,16 +82,16 @@ export const apiFetch = (options) => (query, variables = {}) => {
82
82
  });
83
83
  };
84
84
  export const InternalsBuildQuery = ({ ops, props, returns, options, scalars, }) => {
85
- const ibb = (k, o, p = '', root = true, vars = []) => {
85
+ const ibb = (k, o, p = "", root = true, vars = []) => {
86
86
  const keyForPath = purifyGraphQLKey(k);
87
87
  const newPath = [p, keyForPath].join(SEPARATOR);
88
88
  if (!o) {
89
- return '';
89
+ return "";
90
90
  }
91
- if (typeof o === 'boolean' || typeof o === 'number') {
91
+ if (typeof o === "boolean" || typeof o === "number") {
92
92
  return k;
93
93
  }
94
- if (typeof o === 'string') {
94
+ if (typeof o === "string") {
95
95
  return `${k} ${o}`;
96
96
  }
97
97
  if (Array.isArray(o)) {
@@ -104,29 +104,32 @@ export const InternalsBuildQuery = ({ ops, props, returns, options, scalars, })
104
104
  })(o[0], newPath);
105
105
  return `${ibb(args ? `${k}(${args})` : k, o[1], p, false, vars)}`;
106
106
  }
107
- if (k === '__alias') {
107
+ if (k === "__alias") {
108
108
  return Object.entries(o)
109
109
  .map(([alias, objectUnderAlias]) => {
110
- if (typeof objectUnderAlias !== 'object' || Array.isArray(objectUnderAlias)) {
111
- throw new Error('Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}');
110
+ if (typeof objectUnderAlias !== "object" ||
111
+ Array.isArray(objectUnderAlias)) {
112
+ throw new Error("Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}");
112
113
  }
113
114
  const operationName = Object.keys(objectUnderAlias)[0];
114
115
  const operation = objectUnderAlias[operationName];
115
116
  return ibb(`${alias}:${operationName}`, operation, p, false, vars);
116
117
  })
117
- .join('\n');
118
+ .join("\n");
118
119
  }
119
- const hasOperationName = root && options?.operationName ? ' ' + options.operationName : '';
120
- const keyForDirectives = o.__directives ?? '';
120
+ const hasOperationName = root && options?.operationName ? " " + options.operationName : "";
121
+ const keyForDirectives = o.__directives ?? "";
121
122
  const query = `{${Object.entries(o)
122
- .filter(([k]) => k !== '__directives')
123
+ .filter(([k]) => k !== "__directives")
123
124
  .map((e) => ibb(...e, [p, `field<>${keyForPath}`].join(SEPARATOR), false, vars))
124
- .join('\n')}}`;
125
+ .join("\n")}}`;
125
126
  if (!root) {
126
127
  return `${k} ${keyForDirectives}${hasOperationName} ${query}`;
127
128
  }
128
- const varsString = vars.map((v) => `${v.name}: ${v.graphQLType}`).join(', ');
129
- return `${k} ${keyForDirectives}${hasOperationName}${varsString ? `(${varsString})` : ''} ${query}`;
129
+ const varsString = vars
130
+ .map((v) => `${v.name}: ${v.graphQLType}`)
131
+ .join(", ");
132
+ return `${k} ${keyForDirectives}${hasOperationName}${varsString ? `(${varsString})` : ""} ${query}`;
130
133
  };
131
134
  return ibb;
132
135
  };
@@ -193,7 +196,7 @@ export const Selector = (key) => key && ZeusSelect();
193
196
  export const TypeFromSelector = (key) => key && ZeusSelect();
194
197
  export const Gql = Chain(HOST, {
195
198
  headers: {
196
- 'Content-Type': 'application/json',
199
+ "Content-Type": "application/json",
197
200
  ...HEADERS,
198
201
  },
199
202
  });
@@ -224,12 +227,15 @@ export const traverseResponse = ({ resolvers, scalarPaths, }) => {
224
227
  const scalarPathString = p.join(SEPARATOR);
225
228
  const currentScalarString = scalarPaths[scalarPathString];
226
229
  if (currentScalarString) {
227
- const currentDecoder = resolvers[currentScalarString.split('.')[1]]?.decode;
230
+ const currentDecoder = resolvers[currentScalarString.split(".")[1]]?.decode;
228
231
  if (currentDecoder) {
229
232
  return currentDecoder(o);
230
233
  }
231
234
  }
232
- if (typeof o === 'boolean' || typeof o === 'number' || typeof o === 'string' || !o) {
235
+ if (typeof o === "boolean" ||
236
+ typeof o === "number" ||
237
+ typeof o === "string" ||
238
+ !o) {
233
239
  return o;
234
240
  }
235
241
  const entries = Object.entries(o).map(([k, v]) => [k, ibb(k, v, [...p, purifyGraphQLKey(k)])]);
@@ -241,15 +247,15 @@ export const traverseResponse = ({ resolvers, scalarPaths, }) => {
241
247
  };
242
248
  return ibb;
243
249
  };
244
- export const SEPARATOR = '|';
250
+ export const SEPARATOR = "|";
245
251
  export class GraphQLError extends Error {
246
252
  constructor(response) {
247
- super('');
253
+ super("");
248
254
  this.response = response;
249
255
  console.error(response);
250
256
  }
251
257
  toString() {
252
- return 'GraphQL Response Error';
258
+ return "GraphQL Response Error";
253
259
  }
254
260
  }
255
261
  const ExtractScalar = (mappedParts, returns) => {
@@ -258,7 +264,7 @@ const ExtractScalar = (mappedParts, returns) => {
258
264
  }
259
265
  const oKey = mappedParts[0];
260
266
  const returnP1 = returns[oKey];
261
- if (typeof returnP1 === 'object') {
267
+ if (typeof returnP1 === "object") {
262
268
  const returnP2 = returnP1[mappedParts[1]];
263
269
  if (returnP2) {
264
270
  return ExtractScalar([returnP2, ...mappedParts.slice(2)], returns);
@@ -267,15 +273,17 @@ const ExtractScalar = (mappedParts, returns) => {
267
273
  }
268
274
  return returnP1;
269
275
  };
270
- export const PrepareScalarPaths = ({ ops, returns }) => {
276
+ export const PrepareScalarPaths = ({ ops, returns, }) => {
271
277
  const ibb = (k, originalKey, o, p = [], pOriginals = [], root = true) => {
272
278
  if (!o) {
273
279
  return;
274
280
  }
275
- if (typeof o === 'boolean' || typeof o === 'number' || typeof o === 'string') {
281
+ if (typeof o === "boolean" ||
282
+ typeof o === "number" ||
283
+ typeof o === "string") {
276
284
  const extractionArray = [...pOriginals, originalKey];
277
285
  const isScalar = ExtractScalar(extractionArray, returns);
278
- if (isScalar?.startsWith('scalar')) {
286
+ if (isScalar?.startsWith("scalar")) {
279
287
  const partOfTree = {
280
288
  [[...p, k].join(SEPARATOR)]: isScalar,
281
289
  };
@@ -286,11 +294,12 @@ export const PrepareScalarPaths = ({ ops, returns }) => {
286
294
  if (Array.isArray(o)) {
287
295
  return ibb(k, k, o[1], p, pOriginals, false);
288
296
  }
289
- if (k === '__alias') {
297
+ if (k === "__alias") {
290
298
  return Object.entries(o)
291
299
  .map(([alias, objectUnderAlias]) => {
292
- if (typeof objectUnderAlias !== 'object' || Array.isArray(objectUnderAlias)) {
293
- throw new Error('Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}');
300
+ if (typeof objectUnderAlias !== "object" ||
301
+ Array.isArray(objectUnderAlias)) {
302
+ throw new Error("Invalid alias it should be __alias:{ YOUR_ALIAS_NAME: { OPERATION_NAME: { ...selectors }}}");
294
303
  }
295
304
  const operationName = Object.keys(objectUnderAlias)[0];
296
305
  const operation = objectUnderAlias[operationName];
@@ -303,11 +312,13 @@ export const PrepareScalarPaths = ({ ops, returns }) => {
303
312
  }
304
313
  const keyName = root ? ops[k] : k;
305
314
  return Object.entries(o)
306
- .filter(([k]) => k !== '__directives')
315
+ .filter(([k]) => k !== "__directives")
307
316
  .map(([k, v]) => {
308
317
  // Inline fragments shouldn't be added to the path as they aren't a field
309
318
  const isInlineFragment = originalKey.match(/^...\s*on/) != null;
310
- return ibb(k, k, v, isInlineFragment ? p : [...p, purifyGraphQLKey(keyName || k)], isInlineFragment ? pOriginals : [...pOriginals, purifyGraphQLKey(originalKey)], false);
319
+ return ibb(k, k, v, isInlineFragment ? p : [...p, purifyGraphQLKey(keyName || k)], isInlineFragment
320
+ ? pOriginals
321
+ : [...pOriginals, purifyGraphQLKey(originalKey)], false);
311
322
  })
312
323
  .reduce((a, b) => ({
313
324
  ...a,
@@ -316,47 +327,49 @@ export const PrepareScalarPaths = ({ ops, returns }) => {
316
327
  };
317
328
  return ibb;
318
329
  };
319
- export const purifyGraphQLKey = (k) => k.replace(/\([^)]*\)/g, '').replace(/^[^:]*\:/g, '');
330
+ export const purifyGraphQLKey = (k) => k.replace(/\([^)]*\)/g, "").replace(/^[^:]*\:/g, "");
320
331
  const mapPart = (p) => {
321
- const [isArg, isField] = p.split('<>');
332
+ const [isArg, isField] = p.split("<>");
322
333
  if (isField) {
323
334
  return {
324
335
  v: isField,
325
- __type: 'field',
336
+ __type: "field",
326
337
  };
327
338
  }
328
339
  return {
329
340
  v: isArg,
330
- __type: 'arg',
341
+ __type: "arg",
331
342
  };
332
343
  };
333
344
  export const ResolveFromPath = (props, returns, ops) => {
334
345
  const ResolvePropsType = (mappedParts) => {
335
346
  const oKey = ops[mappedParts[0].v];
336
347
  const propsP1 = oKey ? props[oKey] : props[mappedParts[0].v];
337
- if (propsP1 === 'enum' && mappedParts.length === 1) {
338
- return 'enum';
348
+ if (propsP1 === "enum" && mappedParts.length === 1) {
349
+ return "enum";
339
350
  }
340
- if (typeof propsP1 === 'string' && propsP1.startsWith('scalar.') && mappedParts.length === 1) {
351
+ if (typeof propsP1 === "string" &&
352
+ propsP1.startsWith("scalar.") &&
353
+ mappedParts.length === 1) {
341
354
  return propsP1;
342
355
  }
343
- if (typeof propsP1 === 'object') {
356
+ if (typeof propsP1 === "object") {
344
357
  if (mappedParts.length < 2) {
345
- return 'not';
358
+ return "not";
346
359
  }
347
360
  const propsP2 = propsP1[mappedParts[1].v];
348
- if (typeof propsP2 === 'string') {
361
+ if (typeof propsP2 === "string") {
349
362
  return rpp(`${propsP2}${SEPARATOR}${mappedParts
350
363
  .slice(2)
351
364
  .map((mp) => mp.v)
352
365
  .join(SEPARATOR)}`);
353
366
  }
354
- if (typeof propsP2 === 'object') {
367
+ if (typeof propsP2 === "object") {
355
368
  if (mappedParts.length < 3) {
356
- return 'not';
369
+ return "not";
357
370
  }
358
371
  const propsP3 = propsP2[mappedParts[2].v];
359
- if (propsP3 && mappedParts[2].__type === 'arg') {
372
+ if (propsP3 && mappedParts[2].__type === "arg") {
360
373
  return rpp(`${propsP3}${SEPARATOR}${mappedParts
361
374
  .slice(3)
362
375
  .map((mp) => mp.v)
@@ -367,13 +380,13 @@ export const ResolveFromPath = (props, returns, ops) => {
367
380
  };
368
381
  const ResolveReturnType = (mappedParts) => {
369
382
  if (mappedParts.length === 0) {
370
- return 'not';
383
+ return "not";
371
384
  }
372
385
  const oKey = ops[mappedParts[0].v];
373
386
  const returnP1 = oKey ? returns[oKey] : returns[mappedParts[0].v];
374
- if (typeof returnP1 === 'object') {
387
+ if (typeof returnP1 === "object") {
375
388
  if (mappedParts.length < 2)
376
- return 'not';
389
+ return "not";
377
390
  const returnP2 = returnP1[mappedParts[1].v];
378
391
  if (returnP2) {
379
392
  return rpp(`${returnP2}${SEPARATOR}${mappedParts
@@ -394,15 +407,17 @@ export const ResolveFromPath = (props, returns, ops) => {
394
407
  if (returnP1) {
395
408
  return returnP1;
396
409
  }
397
- return 'not';
410
+ return "not";
398
411
  };
399
412
  return rpp;
400
413
  };
401
414
  export const InternalArgsBuilt = ({ props, ops, returns, scalars, vars, }) => {
402
- const arb = (a, p = '', root = true) => {
403
- if (typeof a === 'string') {
415
+ const arb = (a, p = "", root = true) => {
416
+ if (typeof a === "string") {
404
417
  if (a.startsWith(START_VAR_NAME)) {
405
- const [varName, graphQLType] = a.replace(START_VAR_NAME, '$').split(GRAPHQL_TYPE_SEPARATOR);
418
+ const [varName, graphQLType] = a
419
+ .replace(START_VAR_NAME, "$")
420
+ .split(GRAPHQL_TYPE_SEPARATOR);
406
421
  const v = vars.find((v) => v.name === varName);
407
422
  if (!v) {
408
423
  vars.push({
@@ -419,29 +434,29 @@ export const InternalArgsBuilt = ({ props, ops, returns, scalars, vars, }) => {
419
434
  }
420
435
  }
421
436
  const checkType = ResolveFromPath(props, returns, ops)(p);
422
- if (checkType.startsWith('scalar.')) {
437
+ if (checkType.startsWith("scalar.")) {
423
438
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
424
- const [_, ...splittedScalar] = checkType.split('.');
425
- const scalarKey = splittedScalar.join('.');
439
+ const [_, ...splittedScalar] = checkType.split(".");
440
+ const scalarKey = splittedScalar.join(".");
426
441
  return scalars?.[scalarKey]?.encode?.(a) || JSON.stringify(a);
427
442
  }
428
443
  if (Array.isArray(a)) {
429
- return `[${a.map((arr) => arb(arr, p, false)).join(', ')}]`;
444
+ return `[${a.map((arr) => arb(arr, p, false)).join(", ")}]`;
430
445
  }
431
- if (typeof a === 'string') {
432
- if (checkType === 'enum') {
446
+ if (typeof a === "string") {
447
+ if (checkType === "enum") {
433
448
  return a;
434
449
  }
435
450
  return `${JSON.stringify(a)}`;
436
451
  }
437
- if (typeof a === 'object') {
452
+ if (typeof a === "object") {
438
453
  if (a === null) {
439
454
  return `null`;
440
455
  }
441
456
  const returnedObjectString = Object.entries(a)
442
- .filter(([, v]) => typeof v !== 'undefined')
457
+ .filter(([, v]) => typeof v !== "undefined")
443
458
  .map(([k, v]) => `${k}: ${arb(v, [p, k].join(SEPARATOR), false)}`)
444
- .join(',\n');
459
+ .join(",\n");
445
460
  if (!root) {
446
461
  return `{${returnedObjectString}}`;
447
462
  }
@@ -455,5 +470,8 @@ export const resolverFor = (type, field, fn) => fn;
455
470
  export const START_VAR_NAME = `$ZEUS_VAR`;
456
471
  export const GRAPHQL_TYPE_SEPARATOR = `__$GRAPHQL__`;
457
472
  export const $ = (name, graphqlType) => {
458
- return (START_VAR_NAME + name + GRAPHQL_TYPE_SEPARATOR + graphqlType);
473
+ return (START_VAR_NAME +
474
+ name +
475
+ GRAPHQL_TYPE_SEPARATOR +
476
+ graphqlType);
459
477
  };
@@ -1,3 +1,3 @@
1
- import { TypedDocumentNode } from '@graphql-typed-document-node/core';
2
- import { ValueTypes, GenericOperation, OperationOptions, GraphQLTypes, InputType, ScalarDefinition, ThunderGraphQLOptions, ExtractVariables } from './index.js';
1
+ import { TypedDocumentNode } from "@graphql-typed-document-node/core";
2
+ import { ValueTypes, GenericOperation, OperationOptions, GraphQLTypes, InputType, ScalarDefinition, ThunderGraphQLOptions, ExtractVariables } from "./index.js";
3
3
  export declare const typedGql: <O extends "query" | "mutation", SCLR extends ScalarDefinition, R extends keyof ValueTypes = GenericOperation<O>>(operation: O, graphqlOptions?: ThunderGraphQLOptions<SCLR> | undefined) => <Z extends ValueTypes[R]>(o: Z & { [P in keyof Z]: P extends keyof ValueTypes[R] ? Z[P] : never; }, ops?: OperationOptions) => TypedDocumentNode<InputType<GraphQLTypes[R], Z, SCLR>, ExtractVariables<Z>>;
@@ -1,5 +1,5 @@
1
- import { gql } from 'graphql-tag';
2
- import { Zeus, } from './index.js';
1
+ import { gql } from "graphql-tag";
2
+ import { Zeus, } from "./index.js";
3
3
  export const typedGql = (operation, graphqlOptions) => (o, ops) => {
4
4
  const str = Zeus(operation, o, {
5
5
  operationOptions: ops,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deenruv/reviews-plugin",
3
- "version": "1.0.17-dev.18",
3
+ "version": "1.0.17-dev.23",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -30,9 +30,9 @@
30
30
  "react-router": "^7.13.0",
31
31
  "sonner": "^1.4.41",
32
32
  "recharts": "^2.12.7",
33
- "@deenruv/common": "^1.0.17-dev.18",
34
- "@deenruv/react-ui-devkit": "^1.0.17-dev.18",
35
- "@deenruv/admin-types": "^1.0.17-dev.18"
33
+ "@deenruv/admin-types": "^1.0.17-dev.23",
34
+ "@deenruv/common": "^1.0.17-dev.23",
35
+ "@deenruv/react-ui-devkit": "^1.0.17-dev.23"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@graphql-typed-document-node/core": "3.2.0",
@@ -44,7 +44,7 @@
44
44
  "rimraf": "^5.0.10",
45
45
  "tslib": "^2.6.2",
46
46
  "typescript": "5.3.3",
47
- "@deenruv/core": "^1.0.17-dev.18"
47
+ "@deenruv/core": "^1.0.17-dev.23"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@deenruv/core": "^1.0.0 || ^1.0.17-dev.0"