@cyberskill/shared 2.19.0 → 2.20.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/dist/config/eslint/index.d.ts +5 -0
- package/dist/config/storybook/index.cjs +1 -0
- package/dist/config/storybook/index.d.ts +2 -0
- package/dist/config/storybook/index.js +6 -0
- package/dist/config/storybook/storybook.main.cjs +1 -0
- package/dist/config/storybook/storybook.main.d.ts +17 -0
- package/dist/config/storybook/storybook.main.js +18 -0
- package/dist/config/storybook/storybook.preview.cjs +1 -0
- package/dist/config/storybook/storybook.preview.d.ts +18 -0
- package/dist/config/storybook/storybook.preview.js +39 -0
- package/dist/config/vitest/vitest.e2e.cjs +1 -1
- package/dist/config/vitest/vitest.e2e.js +1 -1
- package/dist/config/vitest/vitest.unit.cjs +1 -1
- package/dist/config/vitest/vitest.unit.js +1 -1
- package/dist/node/cli/index.cjs +2 -2
- package/dist/node/cli/index.js +51 -41
- package/dist/node/express/express.util.cjs +1 -1
- package/dist/node/express/express.util.js +21 -21
- package/dist/node/mongo/mongo.type.d.ts +3 -3
- package/dist/node/mongo/mongo.util.cjs +1 -1
- package/dist/node/mongo/mongo.util.d.ts +1019 -125
- package/dist/node/mongo/mongo.util.js +1 -1
- package/dist/node/path/index.cjs +1 -1
- package/dist/node/path/index.js +27 -25
- package/dist/node/path/path.constant.cjs +1 -1
- package/dist/node/path/path.constant.d.ts +6 -0
- package/dist/node/path/path.constant.js +152 -128
- package/dist/node/storage/index.cjs +1 -1
- package/dist/node/storage/index.d.ts +2 -0
- package/dist/node/storage/index.js +7 -2
- package/dist/node/storage/storage.constant.cjs +1 -0
- package/dist/node/storage/storage.constant.d.ts +4 -0
- package/dist/node/storage/storage.constant.js +7 -0
- package/dist/node/storage/storage.type.d.ts +14 -0
- package/dist/node/storage/storage.util.cjs +1 -1
- package/dist/node/storage/storage.util.d.ts +1 -1
- package/dist/node/storage/storage.util.js +160 -50
- package/dist/react/apollo-client/apollo-client.component.cjs +1 -1
- package/dist/react/apollo-client/apollo-client.component.d.ts +3 -2
- package/dist/react/apollo-client/apollo-client.component.js +12 -12
- package/dist/react/apollo-client/apollo-client.type.d.ts +6 -0
- package/dist/react/apollo-client/apollo-client.util.cjs +1 -1
- package/dist/react/apollo-client/apollo-client.util.js +32 -34
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.cjs +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.d.ts +3 -2
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js +10 -10
- package/dist/react/apollo-error/apollo-error.provider.cjs +1 -1
- package/dist/react/apollo-error/apollo-error.provider.d.ts +5 -4
- package/dist/react/apollo-error/apollo-error.provider.js +21 -15
- package/dist/react/apollo-error/apollo-error.type.d.ts +5 -0
- package/dist/react/apollo-error/apollo-error.util.cjs +1 -1
- package/dist/react/apollo-error/apollo-error.util.d.ts +13 -1
- package/dist/react/apollo-error/apollo-error.util.js +15 -7
- package/dist/react/apollo-error/index.cjs +1 -1
- package/dist/react/apollo-error/index.js +8 -6
- package/package.json +45 -41
- /package/dist/node_modules/.pnpm/{vitest@4.0.6_@types_debug@4.1.12_@types_node@24.9.2_jiti@2.6.1_jsdom@27.1.0_sass@1.93.3_tsx@4.20.6_yaml@2.8.1 → vitest@4.0.13_@types_debug@4.1.12_@types_node@24.10.1_jiti@2.6.1_jsdom@27.2.0_sass@1.94.2_tsx@4.20.6_yaml@2.8.1}/node_modules/vitest/dist/config.cjs +0 -0
- /package/dist/node_modules/.pnpm/{vitest@4.0.6_@types_debug@4.1.12_@types_node@24.9.2_jiti@2.6.1_jsdom@27.1.0_sass@1.93.3_tsx@4.20.6_yaml@2.8.1 → vitest@4.0.13_@types_debug@4.1.12_@types_node@24.10.1_jiti@2.6.1_jsdom@27.2.0_sass@1.94.2_tsx@4.20.6_yaml@2.8.1}/node_modules/vitest/dist/config.js +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { default as localForage } from 'localforage';
|
|
2
|
+
export type LocalForageDriver = Parameters<typeof localForage.defineDriver>[0];
|
|
3
|
+
export interface NodeLocalForageOptions {
|
|
4
|
+
driver?: string | string[];
|
|
5
|
+
size?: number;
|
|
6
|
+
version?: number;
|
|
7
|
+
description?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
storeName?: string;
|
|
10
|
+
baseDir?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface NodeFsDriverState {
|
|
13
|
+
baseDir: string;
|
|
14
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("localforage"),o=require("node:fs/promises"),D=require("node:path"),c=require("./storage.constant.cjs"),I=require("../../config/env/env.util.cjs"),s=require("../log/log.util.cjs");var n=(e,r,t)=>new Promise((i,y)=>{var h=u=>{try{v(t.next(u))}catch(_){y(_)}},O=u=>{try{v(t.throw(u))}catch(_){y(_)}},v=u=>u.done?i(u.value):Promise.resolve(u.value).then(h,O);v((t=t.apply(e,r)).next())});const E=I.getEnv(),l={baseDir:E.CYBERSKILL_STORAGE_DIRECTORY};function m(e){return`${encodeURIComponent(e)}${c.STORAGE_KEY_EXTENSION}`}function N(e){return decodeURIComponent(e.slice(0,-c.STORAGE_KEY_EXTENSION.length))}function R(e,r){return D.join(r,m(e))}const d={_driver:c.NODE_FS_DRIVER_NAME,_support:!0,_initStorage(e){return n(this,null,function*(){try{const r=typeof e=="object"&&e!==null&&"baseDir"in e?e.baseDir:void 0;typeof r=="string"&&r.length>0?l.baseDir=r:l.baseDir=E.CYBERSKILL_STORAGE_DIRECTORY,yield o.mkdir(l.baseDir,{recursive:!0})}catch(r){throw s.log.error("[Storage:init]",r),r}})},clear(){return n(this,null,function*(){const{baseDir:e}=l;yield o.rm(e,{recursive:!0,force:!0}),yield o.mkdir(e,{recursive:!0})})},getItem(e){return n(this,null,function*(){const{baseDir:r}=l,t=R(e,r);try{const i=yield o.readFile(t,"utf8");return JSON.parse(i)}catch(i){if(i.code==="ENOENT")return null;throw i}})},iterate(e){return n(this,null,function*(){const r=yield d.keys();let t=1;for(const i of r){const y=yield d.getItem(i),h=e(y,i,t);if(h!==void 0)return h;t+=1}})},key(e){return n(this,null,function*(){var r;return(r=(yield d.keys())[e])!=null?r:null})},keys(){return n(this,null,function*(){const{baseDir:e}=l;try{return(yield o.readdir(e)).filter(t=>t.endsWith(c.STORAGE_KEY_EXTENSION)).map(N)}catch(r){if(r.code==="ENOENT")return[];throw r}})},length(){return n(this,null,function*(){return(yield d.keys()).length})},removeItem(e){return n(this,null,function*(){const{baseDir:r}=l,t=R(e,r);yield o.rm(t,{force:!0})})},setItem(e,r){return n(this,null,function*(){const{baseDir:t}=l,i=R(e,t);return yield o.mkdir(t,{recursive:!0}),yield o.writeFile(i,JSON.stringify(r),"utf8"),r})}};let a=null,S=null;function f(){return n(this,null,function*(){return a?(yield a,S):(a=n(null,null,function*(){yield g.defineDriver(d),l.baseDir=E.CYBERSKILL_STORAGE_DIRECTORY;const e=yield g.getDriver(c.NODE_FS_DRIVER_NAME),r={baseDir:l.baseDir,name:c.STORAGE_INSTANCE_NAME,storeName:c.STORAGE_STORE_NAME};yield e._initStorage(r),S=e}).catch(e=>{throw a=null,e}),yield a,S)})}const T={get(e){return n(this,null,function*(){try{const t=yield(yield f()).getItem(e);return t!=null?t:null}catch(r){return s.catchError(r,{returnValue:null})}})},set(e,r){return n(this,null,function*(){try{yield(yield f()).setItem(e,r)}catch(t){s.catchError(t)}})},remove(e){return n(this,null,function*(){try{yield(yield f()).removeItem(e)}catch(r){s.catchError(r)}})},keys(){return n(this,null,function*(){try{const r=yield(yield f()).keys();return Array.isArray(r)?r:(s.log.warn("[Storage:keys] Invalid keys response:",r),[])}catch(e){return s.catchError(e,{returnValue:[]})}})},getLogLink(e){return n(this,null,function*(){try{return`${D.join(E.CYBERSKILL_STORAGE_DIRECTORY,m(e))} (key: ${e})`}catch(r){return s.catchError(r,{returnValue:null})}})}};exports.storage=T;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Persistent storage utility object for data persistence across application sessions.
|
|
3
|
-
* This object provides methods for storing, retrieving, and managing data using
|
|
3
|
+
* This object provides methods for storing, retrieving, and managing data using localForage,
|
|
4
4
|
* with automatic initialization and error handling.
|
|
5
5
|
*/
|
|
6
6
|
export declare const storage: {
|
|
@@ -1,31 +1,143 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import _ from "localforage";
|
|
2
|
+
import l from "node:fs/promises";
|
|
3
|
+
import g from "node:path";
|
|
4
|
+
import { STORAGE_KEY_EXTENSION as R, NODE_FS_DRIVER_NAME as I, STORAGE_STORE_NAME as p, STORAGE_INSTANCE_NAME as b } from "./storage.constant.js";
|
|
5
|
+
import { getEnv as N } from "../../config/env/env.util.js";
|
|
6
|
+
import { catchError as s, log as S } from "../log/log.util.js";
|
|
7
|
+
var n = (e, r, t) => new Promise((i, d) => {
|
|
8
|
+
var y = (u) => {
|
|
6
9
|
try {
|
|
7
|
-
|
|
8
|
-
} catch (
|
|
9
|
-
|
|
10
|
+
m(t.next(u));
|
|
11
|
+
} catch (v) {
|
|
12
|
+
d(v);
|
|
10
13
|
}
|
|
11
|
-
},
|
|
14
|
+
}, O = (u) => {
|
|
12
15
|
try {
|
|
13
|
-
|
|
14
|
-
} catch (
|
|
15
|
-
|
|
16
|
+
m(t.throw(u));
|
|
17
|
+
} catch (v) {
|
|
18
|
+
d(v);
|
|
16
19
|
}
|
|
17
|
-
},
|
|
18
|
-
|
|
20
|
+
}, m = (u) => u.done ? i(u.value) : Promise.resolve(u.value).then(y, O);
|
|
21
|
+
m((t = t.apply(e, r)).next());
|
|
19
22
|
});
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const h = N(), o = {
|
|
24
|
+
baseDir: h.CYBERSKILL_STORAGE_DIRECTORY
|
|
25
|
+
};
|
|
26
|
+
function k(e) {
|
|
27
|
+
return `${encodeURIComponent(e)}${R}`;
|
|
28
|
+
}
|
|
29
|
+
function T(e) {
|
|
30
|
+
return decodeURIComponent(e.slice(0, -R.length));
|
|
31
|
+
}
|
|
32
|
+
function E(e, r) {
|
|
33
|
+
return g.join(r, k(e));
|
|
34
|
+
}
|
|
35
|
+
const a = {
|
|
36
|
+
_driver: I,
|
|
37
|
+
_support: !0,
|
|
38
|
+
/** Ensures the storage directory exists and respects custom baseDir overrides. */
|
|
39
|
+
_initStorage(e) {
|
|
40
|
+
return n(this, null, function* () {
|
|
41
|
+
try {
|
|
42
|
+
const r = typeof e == "object" && e !== null && "baseDir" in e ? e.baseDir : void 0;
|
|
43
|
+
typeof r == "string" && r.length > 0 ? o.baseDir = r : o.baseDir = h.CYBERSKILL_STORAGE_DIRECTORY, yield l.mkdir(o.baseDir, { recursive: !0 });
|
|
44
|
+
} catch (r) {
|
|
45
|
+
throw S.error("[Storage:init]", r), r;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
/** Deletes all stored entries by recreating the directory. */
|
|
50
|
+
clear() {
|
|
51
|
+
return n(this, null, function* () {
|
|
52
|
+
const { baseDir: e } = o;
|
|
53
|
+
yield l.rm(e, { recursive: !0, force: !0 }), yield l.mkdir(e, { recursive: !0 });
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
/** Reads and parses a stored value; returns null when the file is missing. */
|
|
57
|
+
getItem(e) {
|
|
58
|
+
return n(this, null, function* () {
|
|
59
|
+
const { baseDir: r } = o, t = E(e, r);
|
|
60
|
+
try {
|
|
61
|
+
const i = yield l.readFile(t, "utf8");
|
|
62
|
+
return JSON.parse(i);
|
|
63
|
+
} catch (i) {
|
|
64
|
+
if (i.code === "ENOENT")
|
|
65
|
+
return null;
|
|
66
|
+
throw i;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
/** Iterates through all keys, invoking the iterator until it returns a value. */
|
|
71
|
+
iterate(e) {
|
|
72
|
+
return n(this, null, function* () {
|
|
73
|
+
const r = yield a.keys();
|
|
74
|
+
let t = 1;
|
|
75
|
+
for (const i of r) {
|
|
76
|
+
const d = yield a.getItem(i), y = e(d, i, t);
|
|
77
|
+
if (y !== void 0)
|
|
78
|
+
return y;
|
|
79
|
+
t += 1;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
/** Returns the key name at the given index or null when out of bounds. */
|
|
84
|
+
key(e) {
|
|
85
|
+
return n(this, null, function* () {
|
|
86
|
+
var r;
|
|
87
|
+
return (r = (yield a.keys())[e]) != null ? r : null;
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
/** Lists all stored keys. */
|
|
91
|
+
keys() {
|
|
92
|
+
return n(this, null, function* () {
|
|
93
|
+
const { baseDir: e } = o;
|
|
94
|
+
try {
|
|
95
|
+
return (yield l.readdir(e)).filter((t) => t.endsWith(R)).map(T);
|
|
96
|
+
} catch (r) {
|
|
97
|
+
if (r.code === "ENOENT")
|
|
98
|
+
return [];
|
|
99
|
+
throw r;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
/** Returns the count of stored keys. */
|
|
104
|
+
length() {
|
|
105
|
+
return n(this, null, function* () {
|
|
106
|
+
return (yield a.keys()).length;
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
/** Removes a stored value for the given key. */
|
|
110
|
+
removeItem(e) {
|
|
111
|
+
return n(this, null, function* () {
|
|
112
|
+
const { baseDir: r } = o, t = E(e, r);
|
|
113
|
+
yield l.rm(t, { force: !0 });
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
/** Stores a value as JSON on disk. */
|
|
117
|
+
setItem(e, r) {
|
|
118
|
+
return n(this, null, function* () {
|
|
119
|
+
const { baseDir: t } = o, i = E(e, t);
|
|
120
|
+
return yield l.mkdir(t, { recursive: !0 }), yield l.writeFile(i, JSON.stringify(r), "utf8"), r;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
let c = null, D = null;
|
|
125
|
+
function f() {
|
|
126
|
+
return n(this, null, function* () {
|
|
127
|
+
return c ? (yield c, D) : (c = n(null, null, function* () {
|
|
128
|
+
yield _.defineDriver(a), o.baseDir = h.CYBERSKILL_STORAGE_DIRECTORY;
|
|
129
|
+
const e = yield _.getDriver(I), r = {
|
|
130
|
+
baseDir: o.baseDir,
|
|
131
|
+
name: b,
|
|
132
|
+
storeName: p
|
|
133
|
+
};
|
|
134
|
+
yield e._initStorage(r), D = e;
|
|
135
|
+
}).catch((e) => {
|
|
136
|
+
throw c = null, e;
|
|
137
|
+
}), yield c, D);
|
|
26
138
|
});
|
|
27
139
|
}
|
|
28
|
-
const
|
|
140
|
+
const w = {
|
|
29
141
|
/**
|
|
30
142
|
* Retrieves a value from persistent storage by key.
|
|
31
143
|
* This method fetches data that was previously stored using the set method.
|
|
@@ -34,14 +146,13 @@ const R = {
|
|
|
34
146
|
* @param key - The unique identifier for the stored value.
|
|
35
147
|
* @returns A promise that resolves to the stored value or null if not found.
|
|
36
148
|
*/
|
|
37
|
-
get(
|
|
38
|
-
return
|
|
149
|
+
get(e) {
|
|
150
|
+
return n(this, null, function* () {
|
|
39
151
|
try {
|
|
40
|
-
yield
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return i(e, { returnValue: null });
|
|
152
|
+
const t = yield (yield f()).getItem(e);
|
|
153
|
+
return t != null ? t : null;
|
|
154
|
+
} catch (r) {
|
|
155
|
+
return s(r, { returnValue: null });
|
|
45
156
|
}
|
|
46
157
|
});
|
|
47
158
|
},
|
|
@@ -54,12 +165,12 @@ const R = {
|
|
|
54
165
|
* @param value - The data to store (will be automatically serialized).
|
|
55
166
|
* @returns A promise that resolves when the storage operation is complete.
|
|
56
167
|
*/
|
|
57
|
-
set(
|
|
58
|
-
return
|
|
168
|
+
set(e, r) {
|
|
169
|
+
return n(this, null, function* () {
|
|
59
170
|
try {
|
|
60
|
-
yield
|
|
61
|
-
} catch (
|
|
62
|
-
|
|
171
|
+
yield (yield f()).setItem(e, r);
|
|
172
|
+
} catch (t) {
|
|
173
|
+
s(t);
|
|
63
174
|
}
|
|
64
175
|
});
|
|
65
176
|
},
|
|
@@ -70,12 +181,12 @@ const R = {
|
|
|
70
181
|
* @param key - The unique identifier of the value to remove.
|
|
71
182
|
* @returns A promise that resolves when the removal operation is complete.
|
|
72
183
|
*/
|
|
73
|
-
remove(
|
|
74
|
-
return
|
|
184
|
+
remove(e) {
|
|
185
|
+
return n(this, null, function* () {
|
|
75
186
|
try {
|
|
76
|
-
yield
|
|
77
|
-
} catch (
|
|
78
|
-
|
|
187
|
+
yield (yield f()).removeItem(e);
|
|
188
|
+
} catch (r) {
|
|
189
|
+
s(r);
|
|
79
190
|
}
|
|
80
191
|
});
|
|
81
192
|
},
|
|
@@ -87,13 +198,12 @@ const R = {
|
|
|
87
198
|
* @returns A promise that resolves to an array of storage keys.
|
|
88
199
|
*/
|
|
89
200
|
keys() {
|
|
90
|
-
return
|
|
201
|
+
return n(this, null, function* () {
|
|
91
202
|
try {
|
|
92
|
-
yield
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return i(r, { returnValue: [] });
|
|
203
|
+
const r = yield (yield f()).keys();
|
|
204
|
+
return Array.isArray(r) ? r : (S.warn("[Storage:keys] Invalid keys response:", r), []);
|
|
205
|
+
} catch (e) {
|
|
206
|
+
return s(e, { returnValue: [] });
|
|
97
207
|
}
|
|
98
208
|
});
|
|
99
209
|
},
|
|
@@ -105,16 +215,16 @@ const R = {
|
|
|
105
215
|
* @param key - The storage key to generate a log link for.
|
|
106
216
|
* @returns A promise that resolves to a formatted log link string or null if an error occurs.
|
|
107
217
|
*/
|
|
108
|
-
getLogLink(
|
|
109
|
-
return
|
|
218
|
+
getLogLink(e) {
|
|
219
|
+
return n(this, null, function* () {
|
|
110
220
|
try {
|
|
111
|
-
return `${
|
|
112
|
-
} catch (
|
|
113
|
-
return
|
|
221
|
+
return `${g.join(h.CYBERSKILL_STORAGE_DIRECTORY, k(e))} (key: ${e})`;
|
|
222
|
+
} catch (r) {
|
|
223
|
+
return s(r, { returnValue: null });
|
|
114
224
|
}
|
|
115
225
|
});
|
|
116
226
|
}
|
|
117
227
|
};
|
|
118
228
|
export {
|
|
119
|
-
|
|
229
|
+
w as storage
|
|
120
230
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@apollo/client/react"),e=require("react"),i=require("./apollo-client.context.cjs"),a=require("./apollo-client.util.cjs"),c=require("../apollo-error/apollo-error.provider.cjs"),u=require("../apollo-error/apollo-error.component.cjs"),p=require("react-hot-toast");function m({options:r,children:t,onError:o}){const l=e.useMemo(()=>a.getClient(r!=null?r:{}),[r]);return e.createElement(e.Fragment,null,e.createElement(c.ApolloErrorProvider,{onError:o},e.createElement(i.ApolloClientProvider,{client:l},e.createElement(n.ApolloProvider,{client:l},t)),!o&&e.createElement(u.ApolloErrorComponent,null)),e.createElement(p.Toaster,{position:"top-right"}))}exports.ApolloProvider=m;
|
|
@@ -13,9 +13,10 @@ import { I_ApolloProviderProps } from './apollo-client.type.js';
|
|
|
13
13
|
* - Automatic error handling
|
|
14
14
|
* - Development and production optimizations
|
|
15
15
|
*
|
|
16
|
-
* @param props - Component props containing options and
|
|
16
|
+
* @param props - Component props containing options, children, and optional error override.
|
|
17
17
|
* @param props.options - Apollo Client configuration options.
|
|
18
18
|
* @param props.children - React children that will have access to Apollo Client context.
|
|
19
|
+
* @param props.onError - Optional callback to override the default modal/toast error handling.
|
|
19
20
|
* @returns A React component that provides Apollo Client context to its children.
|
|
20
21
|
*/
|
|
21
|
-
export declare function ApolloProvider({ options, children }: I_ApolloProviderProps): React.JSX.Element;
|
|
22
|
+
export declare function ApolloProvider({ options, children, onError }: I_ApolloProviderProps): React.JSX.Element;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { ApolloProvider as
|
|
2
|
-
import
|
|
1
|
+
import { ApolloProvider as m } from "@apollo/client/react";
|
|
2
|
+
import e, { useMemo as i } from "react";
|
|
3
3
|
import { ApolloClientProvider as n } from "./apollo-client.context.js";
|
|
4
|
-
import { getClient as
|
|
5
|
-
import { ApolloErrorProvider as
|
|
6
|
-
import { ApolloErrorComponent as
|
|
7
|
-
import { Toaster as
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
() =>
|
|
11
|
-
[
|
|
4
|
+
import { getClient as p } from "./apollo-client.util.js";
|
|
5
|
+
import { ApolloErrorProvider as a } from "../apollo-error/apollo-error.provider.js";
|
|
6
|
+
import { ApolloErrorComponent as c } from "../apollo-error/apollo-error.component.js";
|
|
7
|
+
import { Toaster as f } from "react-hot-toast";
|
|
8
|
+
function s({ options: r, children: l, onError: o }) {
|
|
9
|
+
const t = i(
|
|
10
|
+
() => p(r != null ? r : {}),
|
|
11
|
+
[r]
|
|
12
12
|
);
|
|
13
|
-
return /* @__PURE__ */
|
|
13
|
+
return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(a, { onError: o }, /* @__PURE__ */ e.createElement(n, { client: t }, /* @__PURE__ */ e.createElement(m, { client: t }, l)), !o && /* @__PURE__ */ e.createElement(c, null)), /* @__PURE__ */ e.createElement(f, { position: "top-right" }));
|
|
14
14
|
}
|
|
15
15
|
export {
|
|
16
|
-
|
|
16
|
+
s as ApolloProvider
|
|
17
17
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ApolloClient } from '@apollo/client';
|
|
2
2
|
import { ApolloLink } from '@apollo/client/link';
|
|
3
|
+
import { GraphQLError } from 'graphql';
|
|
3
4
|
import { I_Children } from '../../typescript/index.js';
|
|
4
5
|
export interface I_ApolloOptions extends Omit<ApolloClient.Options, 'link' | 'cache'> {
|
|
5
6
|
uri?: string;
|
|
@@ -9,5 +10,10 @@ export interface I_ApolloOptions extends Omit<ApolloClient.Options, 'link' | 'ca
|
|
|
9
10
|
export interface I_ApolloProviderProps extends I_Children {
|
|
10
11
|
isNextJS?: boolean;
|
|
11
12
|
options?: I_ApolloOptions;
|
|
13
|
+
/**
|
|
14
|
+
* Optional callback to override the default Apollo error modal/toast handling.
|
|
15
|
+
* When provided, the consumer is responsible for surfacing GraphQL errors.
|
|
16
|
+
*/
|
|
17
|
+
onError?: (error: GraphQLError | Error) => void;
|
|
12
18
|
}
|
|
13
19
|
export type { ApolloCache, ApolloClient, ErrorLike } from '@apollo/client';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@apollo/client/core"),p=require("@apollo/client/link"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@apollo/client/core"),p=require("@apollo/client/link"),h=require("@apollo/client/link/error"),y=require("@apollo/client/link/remove-typename"),q=require("@apollo/client/link/subscriptions"),E=require("graphql"),b=require("graphql-ws"),f=require("react"),v=require("rxjs"),m=require("./apollo-client.constant.cjs"),d=require("./apollo-client.module.scss.cjs"),A=require("./links/upload.cjs"),c=require("../apollo-error/apollo-error.util.cjs"),i=require("../log/log.util.cjs"),L=require("react-hot-toast");var C=Object.defineProperty,g=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,k=(e,r,o)=>r in e?C(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,T=(e,r)=>{for(var o in r||(r={}))P.call(r,o)&&k(e,o,r[o]);if(g)for(var o of g(r))O.call(r,o)&&k(e,o,r[o]);return e};const N=new p.ApolloLink((e,r)=>(e.setContext({start:new Date}),r(e).pipe(v.tap(()=>{const o=new Date().getTime()-e.getContext().start;i.log.info(`Operation ${e.operationName} took ${o}ms to complete`)})))),$=new h.ErrorLink(({error:e,operation:r})=>{const o=(r==null?void 0:r.operationName)||"Unknown";let t="";a.CombinedGraphQLErrors.is(e)?e.errors.forEach(({message:l,locations:n,path:s},u)=>{u===0&&(t=l),i.log.error(`[GraphQL error] ${o}: ${l}, Location: ${JSON.stringify(n,null,4)}, Path: ${s}`)}):a.CombinedProtocolErrors.is(e)?e.errors.forEach(({message:l,extensions:n},s)=>{s===0&&(t=l),i.log.error(`[Protocol error]: ${l}, Extensions: ${JSON.stringify(n,null,4)}`)}):a.ServerError.is(e)?(t=e.message,i.log.error(`[Server error]: ${e.message}`)):(t=e.message,i.log.error(`[Network error]: ${e.message}`)),e&&t&&typeof window!="undefined"&&(c.hasCustomApolloErrorHandler()?c.showGlobalApolloError(e):L.toast.error(l=>f.createElement("div",{className:d.default["error-container"]},t,f.createElement("button",{type:"button",className:d.default["error-details-button"],onClick:()=>{c.showGlobalApolloError(e),L.toast.dismiss(l.id)}},"Error Details"))))});function w(e){const{uri:r,wsUrl:o,customLinks:t}=e,l=new y.RemoveTypenameFromVariablesLink;r||i.log.warn(`[Apollo] No GraphQL URI provided — using "${m.GRAPHQL_URI_DEFAULT}" as default`);const n=A.createUploadLink({uri:r!=null?r:m.GRAPHQL_URI_DEFAULT,credentials:"include",headers:{"apollo-require-preflight":"true"}}),s=o?new q.GraphQLWsLink(b.createClient({url:o})):p.ApolloLink.empty(),u=o?p.ApolloLink.split(({operationType:_})=>_===E.OperationTypeNode.SUBSCRIPTION,s,n):n;return o&&u===n&&i.log.warn("[Apollo] WS URL is set, but subscriptions fallback to HTTP. Check your wsLink config."),[N,$,l,...t!=null?t:[],u]}function S(e){const r=p.ApolloLink.from(w(e));return new a.ApolloClient(T({link:r,cache:new a.InMemoryCache},e))}exports.createApolloLinks=w;exports.getClient=S;
|
|
@@ -1,86 +1,84 @@
|
|
|
1
|
-
import { ApolloClient as
|
|
1
|
+
import { ApolloClient as y, InMemoryCache as h, CombinedGraphQLErrors as g, CombinedProtocolErrors as E, ServerError as v } from "@apollo/client/core";
|
|
2
2
|
import { ApolloLink as m } from "@apollo/client/link";
|
|
3
|
-
import { ErrorLink as
|
|
4
|
-
import { RemoveTypenameFromVariablesLink as
|
|
5
|
-
import { GraphQLWsLink as
|
|
6
|
-
import { OperationTypeNode as
|
|
7
|
-
import { createClient as
|
|
3
|
+
import { ErrorLink as _ } from "@apollo/client/link/error";
|
|
4
|
+
import { RemoveTypenameFromVariablesLink as O } from "@apollo/client/link/remove-typename";
|
|
5
|
+
import { GraphQLWsLink as P } from "@apollo/client/link/subscriptions";
|
|
6
|
+
import { OperationTypeNode as b } from "graphql";
|
|
7
|
+
import { createClient as C } from "graphql-ws";
|
|
8
8
|
import p from "react";
|
|
9
9
|
import { tap as N } from "rxjs";
|
|
10
10
|
import { GRAPHQL_URI_DEFAULT as f } from "./apollo-client.constant.js";
|
|
11
11
|
import c from "./apollo-client.module.scss.js";
|
|
12
|
-
import { createUploadLink as
|
|
13
|
-
import { showGlobalApolloError as
|
|
12
|
+
import { createUploadLink as $ } from "./links/upload.js";
|
|
13
|
+
import { hasCustomApolloErrorHandler as A, showGlobalApolloError as u } from "../apollo-error/apollo-error.util.js";
|
|
14
14
|
import { log as s } from "../log/log.util.js";
|
|
15
|
-
import { toast as
|
|
16
|
-
var
|
|
15
|
+
import { toast as d } from "react-hot-toast";
|
|
16
|
+
var S = Object.defineProperty, w = Object.getOwnPropertySymbols, T = Object.prototype.hasOwnProperty, U = Object.prototype.propertyIsEnumerable, L = (r, e, o) => e in r ? S(r, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : r[e] = o, I = (r, e) => {
|
|
17
17
|
for (var o in e || (e = {}))
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
for (var o of
|
|
21
|
-
|
|
18
|
+
T.call(e, o) && L(r, o, e[o]);
|
|
19
|
+
if (w)
|
|
20
|
+
for (var o of w(e))
|
|
21
|
+
U.call(e, o) && L(r, o, e[o]);
|
|
22
22
|
return r;
|
|
23
23
|
};
|
|
24
|
-
const
|
|
24
|
+
const R = new m((r, e) => (r.setContext({ start: /* @__PURE__ */ new Date() }), e(r).pipe(
|
|
25
25
|
N(() => {
|
|
26
26
|
const o = (/* @__PURE__ */ new Date()).getTime() - r.getContext().start;
|
|
27
27
|
s.info(`Operation ${r.operationName} took ${o}ms to complete`);
|
|
28
28
|
})
|
|
29
|
-
))),
|
|
29
|
+
))), G = new _(({ error: r, operation: e }) => {
|
|
30
30
|
const o = (e == null ? void 0 : e.operationName) || "Unknown";
|
|
31
31
|
let t = "";
|
|
32
32
|
g.is(r) ? r.errors.forEach(({ message: n, locations: i, path: l }, a) => {
|
|
33
33
|
a === 0 && (t = n), s.error(
|
|
34
34
|
`[GraphQL error] ${o}: ${n}, Location: ${JSON.stringify(i, null, 4)}, Path: ${l}`
|
|
35
35
|
);
|
|
36
|
-
}) :
|
|
36
|
+
}) : E.is(r) ? r.errors.forEach(({ message: n, extensions: i }, l) => {
|
|
37
37
|
l === 0 && (t = n), s.error(
|
|
38
38
|
`[Protocol error]: ${n}, Extensions: ${JSON.stringify(i, null, 4)}`
|
|
39
39
|
);
|
|
40
|
-
}) : v.is(r) ? (t = r.message, s.error(`[Server error]: ${r.message}`)) : (t = r.message, s.error(`[Network error]: ${r.message}`)), r && t && typeof window != "undefined" && u.error((n) => /* @__PURE__ */ p.createElement("div", { className: c["error-container"] }, t, /* @__PURE__ */ p.createElement(
|
|
40
|
+
}) : v.is(r) ? (t = r.message, s.error(`[Server error]: ${r.message}`)) : (t = r.message, s.error(`[Network error]: ${r.message}`)), r && t && typeof window != "undefined" && (A() ? u(r) : d.error((n) => /* @__PURE__ */ p.createElement("div", { className: c["error-container"] }, t, /* @__PURE__ */ p.createElement(
|
|
41
41
|
"button",
|
|
42
42
|
{
|
|
43
43
|
type: "button",
|
|
44
44
|
className: c["error-details-button"],
|
|
45
45
|
onClick: () => {
|
|
46
|
-
|
|
47
|
-
$(r);
|
|
48
|
-
}, 0), u.dismiss(n.id);
|
|
46
|
+
u(r), d.dismiss(n.id);
|
|
49
47
|
}
|
|
50
48
|
},
|
|
51
49
|
"Error Details"
|
|
52
|
-
)));
|
|
50
|
+
))));
|
|
53
51
|
});
|
|
54
|
-
function
|
|
55
|
-
const { uri: e, wsUrl: o, customLinks: t } = r, n = new
|
|
52
|
+
function Q(r) {
|
|
53
|
+
const { uri: e, wsUrl: o, customLinks: t } = r, n = new O();
|
|
56
54
|
e || s.warn(`[Apollo] No GraphQL URI provided — using "${f}" as default`);
|
|
57
|
-
const i =
|
|
55
|
+
const i = $({
|
|
58
56
|
uri: e != null ? e : f,
|
|
59
57
|
credentials: "include",
|
|
60
58
|
headers: {
|
|
61
59
|
"apollo-require-preflight": "true"
|
|
62
60
|
}
|
|
63
|
-
}), l = o ? new
|
|
64
|
-
({ operationType:
|
|
61
|
+
}), l = o ? new P(C({ url: o })) : m.empty(), a = o ? m.split(
|
|
62
|
+
({ operationType: k }) => k === b.SUBSCRIPTION,
|
|
65
63
|
l,
|
|
66
64
|
i
|
|
67
65
|
) : i;
|
|
68
66
|
return o && a === i && s.warn("[Apollo] WS URL is set, but subscriptions fallback to HTTP. Check your wsLink config."), [
|
|
69
|
-
I,
|
|
70
67
|
R,
|
|
68
|
+
G,
|
|
71
69
|
n,
|
|
72
70
|
...t != null ? t : [],
|
|
73
71
|
a
|
|
74
72
|
];
|
|
75
73
|
}
|
|
76
|
-
function
|
|
77
|
-
const e = m.from(
|
|
78
|
-
return new
|
|
74
|
+
function Z(r) {
|
|
75
|
+
const e = m.from(Q(r));
|
|
76
|
+
return new y(I({
|
|
79
77
|
link: e,
|
|
80
|
-
cache: new
|
|
78
|
+
cache: new h()
|
|
81
79
|
}, r));
|
|
82
80
|
}
|
|
83
81
|
export {
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
Q as createApolloLinks,
|
|
83
|
+
Z as getClient
|
|
86
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@apollo/client-integration-nextjs"),e=require("react"),i=require("./apollo-client-nextjs.util.cjs"),a=require("../apollo-error/apollo-error.provider.cjs"),p=require("../apollo-error/apollo-error.component.cjs"),u=require("react-hot-toast");function c({options:r,children:o,onError:t}){const l=e.useMemo(()=>()=>i.getClient(r||{}),[r]);return e.createElement(e.Fragment,null,e.createElement(a.ApolloErrorProvider,{onError:t},e.createElement(n.ApolloNextAppProvider,{makeClient:l},o),!t&&e.createElement(p.ApolloErrorComponent,null)),e.createElement(u.Toaster,{position:"top-right"}))}exports.ApolloProvider=c;
|
|
@@ -13,9 +13,10 @@ import { I_ApolloProviderProps } from '../apollo-client/index.js';
|
|
|
13
13
|
* - Automatic error handling
|
|
14
14
|
* - Next.js specific optimizations
|
|
15
15
|
*
|
|
16
|
-
* @param props - Component props containing options and
|
|
16
|
+
* @param props - Component props containing options, children, and optional error override.
|
|
17
17
|
* @param props.options - Apollo Client configuration options.
|
|
18
18
|
* @param props.children - React children that will have access to Apollo Client context.
|
|
19
|
+
* @param props.onError - Optional callback to override the default modal/toast error handling.
|
|
19
20
|
* @returns A React component that provides Apollo Client context to its children.
|
|
20
21
|
*/
|
|
21
|
-
export declare function ApolloProvider({ options, children }: I_ApolloProviderProps): React.JSX.Element;
|
|
22
|
+
export declare function ApolloProvider({ options, children, onError }: I_ApolloProviderProps): React.JSX.Element;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { ApolloNextAppProvider as l } from "@apollo/client-integration-nextjs";
|
|
2
|
-
import e, { useMemo as
|
|
3
|
-
import { getClient as
|
|
4
|
-
import { ApolloErrorProvider as
|
|
5
|
-
import { ApolloErrorComponent as
|
|
6
|
-
import { Toaster as
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
() => () =>
|
|
2
|
+
import e, { useMemo as n } from "react";
|
|
3
|
+
import { getClient as p } from "./apollo-client-nextjs.util.js";
|
|
4
|
+
import { ApolloErrorProvider as i } from "../apollo-error/apollo-error.provider.js";
|
|
5
|
+
import { ApolloErrorComponent as a } from "../apollo-error/apollo-error.component.js";
|
|
6
|
+
import { Toaster as c } from "react-hot-toast";
|
|
7
|
+
function s({ options: r, children: t, onError: o }) {
|
|
8
|
+
const m = n(
|
|
9
|
+
() => () => p(r || {}),
|
|
10
10
|
[r]
|
|
11
11
|
);
|
|
12
|
-
return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
|
|
12
|
+
return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(i, { onError: o }, /* @__PURE__ */ e.createElement(l, { makeClient: m }, t), !o && /* @__PURE__ */ e.createElement(a, null)), /* @__PURE__ */ e.createElement(c, { position: "top-right" }));
|
|
13
13
|
}
|
|
14
14
|
export {
|
|
15
|
-
|
|
15
|
+
s as ApolloProvider
|
|
16
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),i=require("./apollo-error.context.cjs"),c=require("./apollo-error.util.cjs");function b({children:n,onError:e}){const[o,t]=l.useState(null),r=l.useCallback(u=>{if(e){e(u);return}t(u)},[e]);l.useEffect(()=>(c.setGlobalApolloErrorCallback(r,!!e),()=>{c.clearGlobalApolloErrorCallback()}),[r,e]);const a=l.useCallback(()=>t(null),[]),s=l.useMemo(()=>({error:e?null:o,showError:r,hideError:a}),[o,r,a,e]);return l.createElement(i.ApolloErrorContext,{value:s},n)}exports.ApolloErrorProvider=b;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { I_ApolloErrorProviderProps } from './apollo-error.type.js';
|
|
2
3
|
/**
|
|
3
4
|
* Provider component that manages Apollo error state and provides error context.
|
|
4
5
|
* This component sets up error handling for Apollo Client operations and provides
|
|
@@ -8,12 +9,12 @@ import { ReactNode, default as React } from 'react';
|
|
|
8
9
|
* - Global Apollo error state management
|
|
9
10
|
* - Error context provision to child components
|
|
10
11
|
* - Automatic error handling and display
|
|
12
|
+
* - Optional custom error handling callbacks
|
|
11
13
|
* - Integration with error boundaries
|
|
12
14
|
*
|
|
13
15
|
* @param props - Component props containing children.
|
|
14
16
|
* @param props.children - React children that will have access to the error context.
|
|
17
|
+
* @param props.onError - Optional callback to override the default error modal/toast flow.
|
|
15
18
|
* @returns A React component that provides Apollo error context to its children.
|
|
16
19
|
*/
|
|
17
|
-
export declare function ApolloErrorProvider({ children }:
|
|
18
|
-
children: ReactNode;
|
|
19
|
-
}): React.JSX.Element;
|
|
20
|
+
export declare function ApolloErrorProvider({ children, onError }: I_ApolloErrorProviderProps): React.JSX.Element;
|