@okam/directus-query 1.1.1 → 1.2.0

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/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './lib/hooks';
2
2
  export * from './lib/query';
3
+ export { logger as DirectusQueryLogger } from './logger';
3
4
  export { default as initDirectusQuery } from './lib/init';
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@tanstack/react-query"),l=require("radash"),a=require("graphql-request"),y=process.env.NEXT_PUBLIC_GRAPHQL_URL,q=process.env.NEXT_GRAPHQL_URL_ADMIN,Q=process.env.NEXT_PUBLIC_API_TOKEN??"",_=process.env.NEXT_PUBLIC_API_TOKEN,A=new a.GraphQLClient(y,{credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${Q}`}}),N=new a.GraphQLClient(q,{credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${_}`}});new t.QueryClient({queryCache:new t.QueryCache({onError:e=>{console.error(e)}}),defaultOptions:{queries:{staleTime:5*1e3}}});function c(e,r,n=A){return n.request(e,{...r})}function o(e,r){return[l.get(e,"definitions.0.name.value"),r]}function p(e,r,n,s){const u=o(e,r);return t.useQuery({queryKey:u,queryFn:async({queryKey:i})=>c(e,i[1],s),...n})}function T(e,r,n){const s=o(e,r);return t.useSuspenseQuery({queryKey:s,queryFn:async({queryKey:u})=>c(e,u[1]),...n})}function G(e,r,n){const s=o(e,r);return t.useSuspenseQuery({queryKey:s,queryFn:async({queryKey:u})=>c(e,u[1],N),...n})}const d=process.env.NEXT_PUBLIC_GRAPHQL_URL,h=process.env.NEXT_PUBLIC_API_TOKEN,P={credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${h}`}},L=(e=d,r=P)=>{const n=new a.GraphQLClient(e,r);function s(u,i){return c(u,i,n)}return{queryGql:s,client:n}};exports.getQueryValues=o;exports.initDirectusQuery=L;exports.queryGql=c;exports.useGqlQuery=p;exports.useSuspenseGqlQuery=T;exports.useSuspenseGqlQueryAdmin=G;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@tanstack/react-query"),p=require("radash"),l=require("graphql-request");class u{constructor(s,e,r){this.nameSpace="[STACK]",this.suppressConsole=!1,this.env=process.env.NODE_ENV,this.nameSpace=s??this.nameSpace,this.suppressConsole=r??this.suppressConsole,this.logger=e??this.internalLogger}internalLogger(s,e,r){this.env!=="production"&&console[e||"log"](`${this.nameSpace} ${s}`.trimStart(),r)}setLogger(s){this.logger=(e,r,t)=>{this.suppressConsole&&this.internalLogger(e,r,t),s(e,r,t)}}static getInstance(){return u.instance||(u.instance=new u),u.instance}log(s,e,r){this.logger(s,e,r)}}u.getInstance();const h=(n,s,e=!1)=>{const r=new u(n,s,e);return r.log("Logger initialized","info"),r},y=h("[DirectusQuery]"),g=process.env.NEXT_PUBLIC_GRAPHQL_URL,q=process.env.NEXT_SERVER_GRAPHQL_URL,Q=process.env.NEXT_GRAPHQL_URL_ADMIN,_=process.env.NEXT_PUBLIC_API_TOKEN??"",N=process.env.NEXT_PUBLIC_API_TOKEN,E=new l.GraphQLClient(q||g,{credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${_}`}}),L=new l.GraphQLClient(Q,{credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${N}`}});new o.QueryClient({queryCache:new o.QueryCache({onError:n=>{y.log("QueryClient Error","error",{error:n})}}),defaultOptions:{queries:{staleTime:5*1e3}}});function i(n,s,e=E){return e.request(n,{...s})}function c(n,s){return[p.get(n,"definitions.0.name.value"),s]}function A(n,s,e,r){const t=c(n,s);return o.useQuery({queryKey:t,queryFn:async({queryKey:a})=>i(n,a[1],r),...e})}function T(n,s,e){const r=c(n,s);return o.useSuspenseQuery({queryKey:r,queryFn:async({queryKey:t})=>i(n,t[1]),...e})}function P(n,s,e){const r=c(n,s);return o.useSuspenseQuery({queryKey:r,queryFn:async({queryKey:t})=>i(n,t[1],L),...e})}const G=process.env.NEXT_PUBLIC_GRAPHQL_URL,d=process.env.NEXT_PUBLIC_API_TOKEN,f={credentials:"include",mode:"cors",fetch,headers:{Authorization:`Bearer ${d}`}},C=(n=G,s=f)=>{const e=new l.GraphQLClient(n,s);function r(t,a){return i(t,a,e)}return{queryGql:r,client:e}};exports.DirectusQueryLogger=y;exports.getQueryValues=c;exports.initDirectusQuery=C;exports.queryGql=i;exports.useGqlQuery=A;exports.useSuspenseGqlQuery=T;exports.useSuspenseGqlQueryAdmin=P;
package/index.mjs CHANGED
@@ -1,25 +1,48 @@
1
- import { QueryClient as l, QueryCache as _, useQuery as y, useSuspenseQuery as a } from "@tanstack/react-query";
2
- import { get as q } from "radash";
1
+ import { QueryClient as p, QueryCache as h, useQuery as _, useSuspenseQuery as l } from "@tanstack/react-query";
2
+ import { get as g } from "radash";
3
3
  import { GraphQLClient as c } from "graphql-request";
4
- const N = process.env.NEXT_PUBLIC_GRAPHQL_URL, A = process.env.NEXT_GRAPHQL_URL_ADMIN, T = process.env.NEXT_PUBLIC_API_TOKEN ?? "", p = process.env.NEXT_PUBLIC_API_TOKEN, P = new c(N, {
4
+ class o {
5
+ constructor(n, e, s) {
6
+ this.nameSpace = "[STACK]", this.suppressConsole = !1, this.env = process.env.NODE_ENV, this.nameSpace = n ?? this.nameSpace, this.suppressConsole = s ?? this.suppressConsole, this.logger = e ?? this.internalLogger;
7
+ }
8
+ internalLogger(n, e, s) {
9
+ this.env !== "production" && console[e || "log"](`${this.nameSpace} ${n}`.trimStart(), s);
10
+ }
11
+ setLogger(n) {
12
+ this.logger = (e, s, t) => {
13
+ this.suppressConsole && this.internalLogger(e, s, t), n(e, s, t);
14
+ };
15
+ }
16
+ static getInstance() {
17
+ return o.instance || (o.instance = new o()), o.instance;
18
+ }
19
+ log(n, e, s) {
20
+ this.logger(n, e, s);
21
+ }
22
+ }
23
+ o.getInstance();
24
+ const y = (r, n, e = !1) => {
25
+ const s = new o(r, n, e);
26
+ return s.log("Logger initialized", "info"), s;
27
+ }, N = y("[DirectusQuery]"), E = process.env.NEXT_PUBLIC_GRAPHQL_URL, A = process.env.NEXT_SERVER_GRAPHQL_URL, L = process.env.NEXT_GRAPHQL_URL_ADMIN, f = process.env.NEXT_PUBLIC_API_TOKEN ?? "", Q = process.env.NEXT_PUBLIC_API_TOKEN, T = new c(A || E, {
5
28
  credentials: "include",
6
29
  mode: "cors",
7
30
  fetch,
8
31
  headers: {
9
- Authorization: `Bearer ${T}`
32
+ Authorization: `Bearer ${f}`
10
33
  }
11
- }), Q = new c(A, {
34
+ }), q = new c(L, {
12
35
  credentials: "include",
13
36
  mode: "cors",
14
37
  fetch,
15
38
  headers: {
16
- Authorization: `Bearer ${p}`
39
+ Authorization: `Bearer ${Q}`
17
40
  }
18
41
  });
19
- new l({
20
- queryCache: new _({
21
- onError: (e) => {
22
- console.error(e);
42
+ new p({
43
+ queryCache: new h({
44
+ onError: (r) => {
45
+ N.log("QueryClient Error", "error", { error: r });
23
46
  }
24
47
  }),
25
48
  defaultOptions: {
@@ -28,60 +51,61 @@ new l({
28
51
  }
29
52
  }
30
53
  });
31
- function u(e, r, n = P) {
32
- return n.request(e, {
33
- ...r
54
+ function i(r, n, e = T) {
55
+ return e.request(r, {
56
+ ...n
34
57
  });
35
58
  }
36
- function i(e, r) {
37
- return [q(e, "definitions.0.name.value"), r];
59
+ function a(r, n) {
60
+ return [g(r, "definitions.0.name.value"), n];
38
61
  }
39
- function G(e, r, n, s) {
40
- const t = i(e, r);
41
- return y({
62
+ function G(r, n, e, s) {
63
+ const t = a(r, n);
64
+ return _({
42
65
  queryKey: t,
43
- queryFn: async ({ queryKey: o }) => u(e, o[1], s),
44
- ...n
66
+ queryFn: async ({ queryKey: u }) => i(r, u[1], s),
67
+ ...e
45
68
  });
46
69
  }
47
- function v(e, r, n) {
48
- const s = i(e, r);
49
- return a({
70
+ function m(r, n, e) {
71
+ const s = a(r, n);
72
+ return l({
50
73
  queryKey: s,
51
- queryFn: async ({ queryKey: t }) => u(e, t[1]),
52
- ...n
74
+ queryFn: async ({ queryKey: t }) => i(r, t[1]),
75
+ ...e
53
76
  });
54
77
  }
55
- function C(e, r, n) {
56
- const s = i(e, r);
57
- return a({
78
+ function U(r, n, e) {
79
+ const s = a(r, n);
80
+ return l({
58
81
  queryKey: s,
59
- queryFn: async ({ queryKey: t }) => u(e, t[1], Q),
60
- ...n
82
+ queryFn: async ({ queryKey: t }) => i(r, t[1], q),
83
+ ...e
61
84
  });
62
85
  }
63
- const f = process.env.NEXT_PUBLIC_GRAPHQL_URL, E = process.env.NEXT_PUBLIC_API_TOKEN, L = {
86
+ const P = process.env.NEXT_PUBLIC_GRAPHQL_URL, C = process.env.NEXT_PUBLIC_API_TOKEN, I = {
64
87
  credentials: "include",
65
88
  mode: "cors",
66
89
  fetch,
67
90
  headers: {
68
- Authorization: `Bearer ${E}`
91
+ Authorization: `Bearer ${C}`
69
92
  }
70
- }, R = (e = f, r = L) => {
71
- const n = new c(e, r);
72
- function s(t, o) {
73
- return u(t, o, n);
93
+ }, O = (r = P, n = I) => {
94
+ const e = new c(r, n);
95
+ function s(t, u) {
96
+ return i(t, u, e);
74
97
  }
75
98
  return {
76
99
  queryGql: s,
77
- client: n
100
+ client: e
78
101
  };
79
102
  };
80
103
  export {
81
- i as getQueryValues,
82
- R as initDirectusQuery,
83
- u as queryGql,
104
+ N as DirectusQueryLogger,
105
+ a as getQueryValues,
106
+ O as initDirectusQuery,
107
+ i as queryGql,
84
108
  G as useGqlQuery,
85
- v as useSuspenseGqlQuery,
86
- C as useSuspenseGqlQueryAdmin
109
+ m as useSuspenseGqlQuery,
110
+ U as useSuspenseGqlQueryAdmin
87
111
  };
package/lib/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { RequestConfig } from 'graphql-request/build/esm/types';
1
+ import type { RequestConfig } from 'node_modules/graphql-request/build/legacy/helpers/types';
2
2
  export declare const GRAPHQL_ENDPOINT: string;
3
3
  export declare const AUTH_TOKEN: string;
4
4
  export declare const defaultConfig: RequestConfig;
package/lib/init.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { type TypedDocumentNode } from '@graphql-typed-document-node/core';
2
2
  import { GraphQLClient } from 'graphql-request';
3
- import type { Variables } from 'graphql-request';
4
- import type { RequestConfig } from 'graphql-request/build/esm/types';
3
+ import type { RequestConfig } from 'node_modules/graphql-request/build/legacy/helpers/types';
5
4
  declare const initDirectusQuery: (graphqlEndPoint?: string, requestConfig?: RequestConfig) => {
6
- queryGql: <TResult, TVariables extends Variables>(document: TypedDocumentNode<TResult, TVariables>, queryKey?: TVariables | undefined) => Promise<TResult>;
5
+ queryGql: <TResult, TVariables extends object>(document: TypedDocumentNode<TResult, TVariables>, queryKey?: TVariables | undefined) => Promise<TResult>;
7
6
  client: GraphQLClient;
8
7
  };
9
8
  export default initDirectusQuery;
package/lib/request.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { QueryClient } from '@tanstack/react-query';
2
2
  import { GraphQLClient } from 'graphql-request';
3
+ export declare const grapqhlGetDefaultEndpoint: () => string;
4
+ export declare const grapqhlGetDefaultAdminEndpoint: () => string;
3
5
  export declare const graphqlRequestClient: GraphQLClient;
4
6
  export declare const graphqlRequestAdmin: GraphQLClient;
5
7
  export declare const queryClient: QueryClient;
package/logger.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const logger: import("@okam/logger").Logger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okam/directus-query",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
@@ -8,5 +8,11 @@
8
8
  "import": "./index.mjs",
9
9
  "require": "./index.js"
10
10
  }
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "repository": {
16
+ "url": "https://github.com/OKAMca/stack.git"
11
17
  }
12
18
  }