@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 +1 -0
- package/index.js +1 -1
- package/index.mjs +66 -42
- package/lib/config.d.ts +1 -1
- package/lib/init.d.ts +2 -3
- package/lib/request.d.ts +2 -0
- package/logger.d.ts +1 -0
- package/package.json +7 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
|
2
|
-
import { get as
|
|
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
|
-
|
|
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 ${
|
|
32
|
+
Authorization: `Bearer ${f}`
|
|
10
33
|
}
|
|
11
|
-
}),
|
|
34
|
+
}), q = new c(L, {
|
|
12
35
|
credentials: "include",
|
|
13
36
|
mode: "cors",
|
|
14
37
|
fetch,
|
|
15
38
|
headers: {
|
|
16
|
-
Authorization: `Bearer ${
|
|
39
|
+
Authorization: `Bearer ${Q}`
|
|
17
40
|
}
|
|
18
41
|
});
|
|
19
|
-
new
|
|
20
|
-
queryCache: new
|
|
21
|
-
onError: (
|
|
22
|
-
|
|
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
|
|
32
|
-
return
|
|
33
|
-
...
|
|
54
|
+
function i(r, n, e = T) {
|
|
55
|
+
return e.request(r, {
|
|
56
|
+
...n
|
|
34
57
|
});
|
|
35
58
|
}
|
|
36
|
-
function
|
|
37
|
-
return [
|
|
59
|
+
function a(r, n) {
|
|
60
|
+
return [g(r, "definitions.0.name.value"), n];
|
|
38
61
|
}
|
|
39
|
-
function G(
|
|
40
|
-
const t =
|
|
41
|
-
return
|
|
62
|
+
function G(r, n, e, s) {
|
|
63
|
+
const t = a(r, n);
|
|
64
|
+
return _({
|
|
42
65
|
queryKey: t,
|
|
43
|
-
queryFn: async ({ queryKey:
|
|
44
|
-
...
|
|
66
|
+
queryFn: async ({ queryKey: u }) => i(r, u[1], s),
|
|
67
|
+
...e
|
|
45
68
|
});
|
|
46
69
|
}
|
|
47
|
-
function
|
|
48
|
-
const s =
|
|
49
|
-
return
|
|
70
|
+
function m(r, n, e) {
|
|
71
|
+
const s = a(r, n);
|
|
72
|
+
return l({
|
|
50
73
|
queryKey: s,
|
|
51
|
-
queryFn: async ({ queryKey: t }) =>
|
|
52
|
-
...
|
|
74
|
+
queryFn: async ({ queryKey: t }) => i(r, t[1]),
|
|
75
|
+
...e
|
|
53
76
|
});
|
|
54
77
|
}
|
|
55
|
-
function
|
|
56
|
-
const s =
|
|
57
|
-
return
|
|
78
|
+
function U(r, n, e) {
|
|
79
|
+
const s = a(r, n);
|
|
80
|
+
return l({
|
|
58
81
|
queryKey: s,
|
|
59
|
-
queryFn: async ({ queryKey: t }) =>
|
|
60
|
-
...
|
|
82
|
+
queryFn: async ({ queryKey: t }) => i(r, t[1], q),
|
|
83
|
+
...e
|
|
61
84
|
});
|
|
62
85
|
}
|
|
63
|
-
const
|
|
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 ${
|
|
91
|
+
Authorization: `Bearer ${C}`
|
|
69
92
|
}
|
|
70
|
-
},
|
|
71
|
-
const
|
|
72
|
-
function s(t,
|
|
73
|
-
return
|
|
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:
|
|
100
|
+
client: e
|
|
78
101
|
};
|
|
79
102
|
};
|
|
80
103
|
export {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
104
|
+
N as DirectusQueryLogger,
|
|
105
|
+
a as getQueryValues,
|
|
106
|
+
O as initDirectusQuery,
|
|
107
|
+
i as queryGql,
|
|
84
108
|
G as useGqlQuery,
|
|
85
|
-
|
|
86
|
-
|
|
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/
|
|
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 {
|
|
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
|
|
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.
|
|
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
|
}
|